Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timezone to UTC in Play Framework

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 .

like image 218
vamsi Avatar asked Oct 29 '14 07:10

vamsi


1 Answers

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

like image 93
biesior Avatar answered Oct 10 '22 06:10

biesior