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:
Joda-Time uses the accurate time-zone database, which has Local Mean Time (LMT) for years before time-zones started. To quote Wikipedia:
Local mean time is a form of solar time that corrects the variations of local apparent time, forming a uniform time scale at a specific longitude.
The JDK doesn't use LMT, thus the times differ.
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);
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