これは予想よりも簡単でした。
まず、application.confで 、パラメータ別のStackOverflowの質問で説明されているように
:
# Set MySQL Connector/J to use UTC server connection and time conversions
# see https://stackoverflow.com/questions/10488529/gettimestamp-does-timezone-converstion-twice-in-mysql-jdbc-connector
db.default.url="jdbc:mysql://localhost/database?useGmtMillisForDatetimes=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&useTimezone=true&serverTimezone=UTC"
次に、Build.scalaで 、Javaシステムプロパティとデフォルトを設定します:
// Setting this property here forces the JVM to run in UTC time,
// both for test (`play test`) and development (`play start`) modes,
// but not for production (`play dist`).
System.setProperty("user.timezone", "GMT")
TimeZone.setDefault(TimeZone.getTimeZone("GMT"))
これらの2つの変更は、両方のテストを一緒に処理します (play test )および開発 (play start )モード。
本番の場合 (play dist )、起動する前にプロパティを設定する必要があります。例:
- 生成された
startの編集export _JAVA_OPTIONS=-Duser.timezone=GMTを追加するスクリプト -
startを呼び出す-Duser.timezone=GMTを使用したスクリプト -
System.setProperty("user.timezone", "GMT")を呼び出した後、既存のJVM内で起動します