hudi hudi - 6 months ago 11
Java Question

How to convert from java.util.date to JodaTime and get same date

I follow this question: Convert from java.util.date to JodaTime

I have date: Sun Jan 01 00:00:00 CET 1854
now I want to convert it to joda datetime:


DateTime dateTime = new DateTime(date);


and now when I print this date I got:
1853-12-31T23:57:44.000+00:57:44

what is wrong and why my date changed ? How I can get the same date ?

UPDATE:

I get date using calendar:

Calendar cal1 = Calendar.getInstance();
cal1.set(1854, 0, 1, 0, 0, 0);
cal1.getTime()


UPDATE2:

propably there is problem with milseconds:

Calendar cal1 = Calendar.getInstance();
cal1.set(1854, 0, 1, 0, 0, 0);
DateTime start = new DateTime(1854, 1, 1, 0, 0, 0);
System.out.println(start.getMillis());
System.out.println(cal1.getTime().getTime());


because this code return:

-3660598664000
-3660598799438


but I dont know why

UPDATE3:

enter image description here

Answer

ok I solve it. Is isnt nice but it works what is important

  Calendar calendar = Calendar.getInstance();
    calendar.setTime(datum);

    DateTime current = new DateTime(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
            calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);