I have a date column in Excel, but when I'm reading it in my Java application I'm getting the value as number.
Example
Excel Date
1/1/2013
I'm getting it as
41275.00
How to convert the number to a date in my Java application?
On the Home tab, in the Number group, click the Dialog Box Launcher next to Number. You can also press CTRL+1 to open the Format Cells dialog box. In the Category list, click Date or Time. In the Type list, click the date or time format that you want to use.
Convert Excel date to text via NotepadSelect all of the dates you want to convert and press Ctrl+C to copy them. Open Notepad or any other text editor, and paste the copied dates there. Notepad automatically converts the dates to the text format. Press Ctrl+A to select all text strings, and then Ctrl+C to copy them.
Here is a minimal working example how to convert an Excel date to a Java date:
Date javaDate= DateUtil.getJavaDate((double) 41275.00);
System.out.println(new SimpleDateFormat("MM/dd/yyyy").format(javaDate));
which returns
01/01/2013
You also need to import the following packages:
java.text.SimpleDateFormat
java.util.Date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With