A Better DateTime Library for Java
Thursday, 1 November 2007
lshift writes about how difficult it is to use Java’s simple date parser to take into account daylight savings, and offers a workaround. Then refers us to joda, a better java date time library.
SimpleDateFormat assumes, if it’s not told, that what it’s parsing is in the system timezone, so in London the string from before [ed: 3 Oct 2007] is interpreted as midnight on the 3rd of October, British Summer Time; i.e., eleven at night on the 2nd, UTC. That’s not a bad assumption, although I didn’t see it documented anywhere, and fits well with the rest of the formatting APIs and locales and so on. The problem is that there’s no way to stop it behaving like that.