0

I am using this format in Joda-Time:

MM/dd/yyyy HH:mm:ss zzzz

In running my app it prints 12/16/2015 09:52:37 Central Standard Time but in my test it prints 12/16/2015 09:52:37 -07:00.

I found for the pattern zzzz docs say:

Long specific non-location format (e.g. “Pacific Standard Time”).If the localized data is not available, localized GMT format is used (e.g. GMT-08:00).

Does localized refer to locale? I would like to get my test outputting consistent date with what mainline code outputs.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Barry
  • 1,800
  • 2
  • 25
  • 46
  • Check the locale and timezone setting on your production and test machines (eg. these would be the `locale` command and [checking `/etc/timezone` on some distributions](http://stackoverflow.com/q/3118582/466738), also the `date` command can show a difference in the timezone value). Post more about your environment, then it might lead to better answers. – Adam Michalik Dec 16 '15 at 16:58
  • Not sure if this helps but the actual line of code with issues is `new DateTime().toString(DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss zzzz")` I played around with adding a locale to the DateTimeFormatter but getting same results. – Barry Dec 16 '15 at 21:24
  • if you want to put this as an answer I can accept it. I think this was a machine setting and I ended up refactoring code a bit and things started working – Barry Dec 22 '15 at 14:59
  • That documentation quote is actually [from the ICU project](http://userguide.icu-project.org/formatparse/datetime), not Joda-Time. Do we know that Joda-Time uses ICU? – Basil Bourque Dec 22 '15 at 21:43

1 Answers1

2

This is most likely a difference in the server environment on the operating system level. JodaTime and JDK use the "default time zone" for the timestamps if you don't specify one explicitly. The default time zone is the time zone provided by the OS. Check the locale and timezone setting on your production and test machines (eg. these would be the locale command and checking /etc/timezone on some distributions, also the date command can show a difference in the time zone value).

Alternatively, you can query the default time zone used by JodaTime using DateTimeZone.getDefault() which is initialized from JDK's TimeZone.getDefault(). This in turn is initialized at the JVM startup property user.timezone (when not set explicitly, it queries the OS for the time zone). If you want to force the JVM to run in a certain time zone other than the one reported by the OS, you can provide the property at startup time:

java -Duser.timezone=UTC
Community
  • 1
  • 1
Adam Michalik
  • 9,678
  • 13
  • 71
  • 102