How to set timezone to UTC in Play Framework
Asked Answered
H

2

6

I want to set the time zone for the java application written in PlayFramework to UTC

How to set timezone to UTC in Play Framework 2.0 for both production and tests?

I have referred to the above mentioned link but it mentions about the build.scala where as we have build.sbt in playframe work.

so can anyone let me know how to set the java parameters for timezone in build.sbt .

Handspike answered 29/10, 2014 at 7:12 Comment(1)
Add information about your current Play version.Ginger
G
10

As said in several posts (i.e. on the group) it's safest to rely on system's settings and it's the best approach (not only for Play, and not only for Java), anyway if you need to change timezone without changing your OS settings (i.e. devs working in other timezone then target app) you can do it by including JVM option (which is pointed in the topic you cited), i.e. for Play 2.2.x:

play -Duser.timezone=GMT ~run

and for 2.3.x+

./activator -Duser.timezone=GMT ~run

As mentioned in the other topic for dist version you need to modify the generated script OR invoke it with this option.

Warning! setting timezone programmatically after app start (i.e. within the Global class) isn't good option, @see this gist

TIP. of course to avoid disables you can just write a bash script in the app's directory, i.e. run.sh:

#!/bin/bash
./activator -Duser.timezone=GMT -Dhttp.port=12345 ~run

and use it to run the app in dev mode. If using some IDE to run the app, check the configuration window for JVM options

Ginger answered 29/10, 2014 at 7:53 Comment(1)
In the above link they it is mentioned that it is possible to configure the timezone in build.scala as System.setProperty("user.timezone", "GMT") TimeZone.setDefault(TimeZone.getTimeZone("GMT")) . I was wondering if such thing is possible to do in build.sbtHandspike
R
0

Or you can try it like this:

./activator -Duser.timezone=GMT "run 12345"

Here 12345 is your running port for play application.

Relent answered 8/5, 2015 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.