I'm using the Joda time (1.6) libraries and it keeps returning DateTime objects with the wrong time zone, British Summer Time instead of GMT.
My Windows workstation (running JDK 1.6.0_16) thinks it's in GMT and if I get the default time zone from the JDK date/time classes it is correct (GMT). I get the same behaviour on our Linux servers as well. I thought it could be an error in the time zone database files in Joda so I rebuilt the jar with the latest database but with no change.
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
public class TimeZoneTest {
public static void main(String[] args) {
DateTimeFormatter timeParser = ISODateTimeFormat.timeParser();
TimeZone timeZone = TimeZone.getDefault();
System.out.println(timeZone.getID()); // "Europe/London"
System.out.println(timeZone.getDisplayName()); // "Greenwich Mean Time"
DateTimeZone defaultTimeZone = DateTimeZone.getDefault();
System.out.println(defaultTimeZone.getID()); //"Europe/London"
System.out.println(defaultTimeZone.getName(0L)); //"British Summer Time"
DateTime currentTime = new DateTime();
DateTimeZone currentZone = currentTime.getZone();
System.out.println(currentZone.getID()); //"Europe/London"
System.out.println(currentZone.getName(0L)); //"British Summer Time"
}
}
Debugging through the static initialiser in org.joda.time.DateTimeZone
I see that the System.getProperty("user.timezone")
call gives "Europe/London"
as expected.