Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting number representing a date in Excel to a Java Date object

Tags:

java

excel

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?

like image 313
aizaz Avatar asked Sep 26 '13 12:09

aizaz


People also ask

How do I convert a number in Excel to a date?

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.

How do I convert a number to date text?

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.


1 Answers

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
like image 161
cemal Avatar answered Sep 26 '22 06:09

cemal