Question

import org.joda.time.LocalDateTime;
import java.util.Date;

With this date or with the following ones it's all OK:

  • new LocalDateTime(new Date(0,0,1,2,30)) — 1900-01-01T02:30:00.000
  • new LocalDateTime(new Date(111,4,24,19,51)) — 2011-05-24T19:51:00.000

But there is something incomprehensible with preceding dates:

  • new LocalDateTime(new Date(0,0,1,2,29,50)) — 1900-01-01T01:59:50.000
  • new LocalDateTime(new Date(0,0,1)) — 1899-12-31T23:30:00.000
  • new LocalDateTime(new Date(-50,0,1)) — 1849-12-31T23:30:20.000
  • new LocalDateTime(new Date(-116,6,4)) — 1784-07-03T23:30:20.000

Who knows, what is this, and how to prevent this problem?

Was it helpful?

Solution

Which timezone are you using? It looks like you're dealing with a clock discontinuity, possibly around 2 AM on January 1st, 1900. That means a certain amount of time was skipped by the local clock and officially doesn't exist. It could also be a change in DST. The consistent difference in your last 3 lines looks strange though - perhaps Java's Calendar and Joda Time use a different version of the timezone database and the change is missing in one of them.

You can check your timezone for changes at the linked-to site.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top