UTC default timezone for Jodatime DateTime

I am currently creating UTC DateTime objects using the current idiom

DateTime now = new DateTime(DateTimeZone.UTC); 

Is there a default way, so I can create UTC based DateTime objects using the default constructor, so is it more implicit?

 DateTime now = new DateTime(); 
+44
java jodatime
Feb 22 2018-12-22T00:
source share
2 answers

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




If you want to change the time zone that all jvm uses, use the TimeZone.setDefault method. Just remember to install it at an early stage, as it can be cached by joda time. Quote DateTimeZone.getDefault :

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

+57
Feb 22 '12 at 15:31
source share

If you are really worried about extra characters, just create a helper method:

 public static DateTime newUTCDateTime() { return new DateTime(DateTimeZone.UTC); } 
+15
Feb 22 '12 at 15:29
source share



All Articles