Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Read Date from Excel and change its Format

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    46
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Read Date from Excel and change its Format

    Hello,

    i have excel file and i want to read some column and insert it in DB, any way i want to read Column with Date
    PHP Code:
    The column in the Excel filewhich i want to be read

    Date
    ========
    14.12.2010
    15.12.2010
    16.12.2010
    17.12.2010
    18.12.2010
    19.12.2010
    20.12.2010
    21.12.2010
    22.12.2010 
    public class Date_DB {
     
        private String name;
        private Date dateOfCommission;
       //Setters und Getters
    }

    Calss To read from Excel
    Date_DB pp = new Date_DB();
    pp.setDateOfCommission(row.getCell(12).getDateCellValue());  ///date
    set.add(pp);

    But it reads the Date as the flowing:
    HTML Code:
    Tue Dec 14 00:00:00 CET 2010
    Wed Dec 15 00:00:00 CET 2010
    Thu Dec 16 00:00:00 CET 2010
    Fri Dec 17 00:00:00 CET 2010
    Sat Dec 18 00:00:00 CET 2010
    Sun Dec 19 00:00:00 CET 2010
    Mon Dec 20 00:00:00 CET 2010
    Tue Dec 21 00:00:00 CET 2010
    Wed Dec 22 00:00:00 CET 2010
    Now what i wish is to reformat this Date to be exactly like in the Excel file (have Format ""dd.MM.yyyy" ) and store them ad a Date in the Set

    I read a lot about Calender Format, but i didn't find any thing really helpful, i know that, but now i need really to change its format to something like "dd.MM.yyyy", and i know that i should use SimpleDateFormat, but some how i don'nt know how to use it right during reding the Date cells from the excel file

    The Problem that SimpleDateFormat return Type String and i need just to deal with Date
    SimpleDateFormat  sdf = new SimpleDateFormat("dd.MM.yyyy");
    pp.setDateOfCommission(sdf.format(row.getCell(12).getDateCellValue())); // error: The method setDateOfCommission(Date) in the type Date_DB is not applicable for the arguments (String)

    or something like that
    SimpleDateFormat  sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date date = sdf.parse(pp.setDateOfCommission(row.getCell(12).getDateCellValue())); //error: The method parse(String) in the type DateFormat is not applicable for the arguments (void)

    so how to deal with it?

    Any Help?


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Read Date from Excel and change its Format

    Read Date from Excel and change its Format

Similar Threads

  1. How to convert date to different format
    By sebE23 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 30th, 2013, 03:44 AM
  2. change DATE
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 11
    Last Post: December 7th, 2012, 11:44 AM
  3. Java Date Format in Date Object
    By Ashr Raza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 13th, 2012, 10:47 AM
  4. Working out the day from numeric date (dd/mm/yy format).
    By ShaunB in forum Java Theory & Questions
    Replies: 6
    Last Post: April 23rd, 2011, 08:55 PM
  5. date format
    By arunjib in forum Java Theory & Questions
    Replies: 4
    Last Post: March 12th, 2011, 01:42 PM