Defaulting date time zone to UTC for Jodatime's DateTime

Solution 1:

If you only want to set the default timezone for joda time, use DateTimeZone.setDefault.


If you want to change the timezone that the whole jvm uses use TimeZone.setDefault method. Just be sure to set it early as it can be cached by joda time.. quoted from DateTimeZone.getDefault:

The default time zone is derived from the system property user.timezone. If that is null or is not a valid identifier, then the value of the JDK TimeZone default is converted. If that fails, UTC is used.

Solution 2:

If you are really concerned about the extra chars, then just create a helper method:

public static DateTime newUTCDateTime() {
  return new DateTime(DateTimeZone.UTC);
}