DateTime.toDate() wrong

Workbook wb = new Workbook("C:/time.xlsx");
DateTime value = (DateTime) wb.getWorksheets().get(0).getCells().get("A2").getValue();
System.out.println(value);
System.out.println(value.toDate());

Output is :
1900-01-01T00:18:00
Mon Jan 01 00:12:08 CST 1900

The date is wrong when call toDate()

Hi,


Thanks for the template file and sample code.

I have evaluated your issue a bit and observed the issue. Could you also provide the following details, so we could evaluate your issue properly and may log a ticket into our database for investigation and resolution:
1) What is the valid Date/Time it should print when converting the value to DateTime?
2) What is your regional/ locale settings set on your system?


Thank you.
  1. It should be the same as MS Excel or like value.toString() “Mon Jan 01 00:18:00 CST 1900"
    2. My system time zone is :
    sun.util.calendar.ZoneInfo[id=“Asia/Shanghai”,offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null]

    And in System.getProperties()
    user.timezone=
    user.country=CN
    user.language=zh




    If the datetime in year 2016, value.toDate() is fine. Same as value.toString():
    Workbook wb = new Workbook(“C:/time.xlsx”);
    DateTime value = (DateTime) wb.getWorksheets().get(0).getCells().get(“A2”).getValue();
    System.out.println(value);
    System.out.println(value.toDate());
    System.out.println(”----");
    value = (DateTime) wb.getWorksheets().get(0).getCells().get(“A3”).getValue();
    System.out.println(value);
    System.out.println(value.toDate());


    1900-01-01T00:18:00
    Mon Jan 01 00:12:08 CST 1900
    ----
    2016-01-01T00:18:00
    Fri Jan 01 00:18:00 CST 2016

Hi,


Thanks for providing us further details, template file and updated code segment.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found that DateTime.toDate() gives wrong value. I also found that the issue does not occur if the DateTime year is 2016 but it does not give correct DateTime value for the year 1900.
e.g
Sample code:


Workbook wb = new Workbook(“C:/time.xlsx”);
DateTime value = (DateTime) wb.getWorksheets().get(0).getCells().get(“A2”).getValue();
System.out.println(value);
System.out.println(value.toDate());
System.out.println("----");
value = (DateTime) wb.getWorksheets().get(0).getCells().get(“A3”).getValue();
System.out.println(value);
System.out.println(value.toDate());

I have logged a ticket with an id “CELLSJAVA-41742” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan