Format Excel Date in Java

3

I have a question, I hope someone can help me:

In Excel, inside a cell I have a date, for example, today:

2/12/2018

To this cell I give a right click - > Format of cells and format as a number, with which I have the following result:

43439,67

How do I get Java to get this number? I tried with the following code:

Date fecha = new Date();
System.out.println(fecha.getTime());

And I get as a result:

1544043888569
    
asked by David Davila 05.12.2018 в 22:23
source

1 answer

0

Solved with the following code:

Date fecha = new Date();
double dias = fecha.getTime() / 1000.0 / 86400 + 70 * 365.25 + 1;
System.out.println(dias);

The "getTime ()" function returns the number of milliseconds from 1/1/1970 to the present date; on the other hand Excel returns the number of days since 12/31/1899 until the present date; therefore, what is done is a conversion.

    
answered by 06.12.2018 / 00:31
source