Joda Time UTC DateTime オブジェクトを現地時間に変換したいと考えています。
これは、うまくいくように見える面倒な方法です。しかし、もっと良い方法があるはずです。
以下は、宣言を囲んでいないコード (Scala の場合) です。
val dtUTC = new DateTime("2010-10-28T04:00")
println("dtUTC = " + dtUTC)
val dtLocal = timestampLocal(dtUTC)
println("local = " + dtLocal)
def timestampLocal(dtUTC: DateTime): String = {
// This is a laborious way to convert from UTC to local. There must be a better way.
val instantUTC = dtUTC.getMillis
val localDateTimeZone = DateTimeZone.getDefault
val instantLocal = localDateTimeZone.convertUTCToLocal(instantUTC)
val dtLocal = new DateTime(instantLocal)
dtLocal.toString
}
出力は次のとおりです。
dtUTC = 2010-10-28T04:00:00.000+11:00 ローカル = 2010-10-28T15:00:00.000+11:00