タイムゾーンをとして設定したユーザーがいますAmerica/New_York
。私は彼のために、彼の真夜中に開始し、24時間後(次の真夜中)に終了するイベントをスケジュールする必要があります。しかし、私はデータベースに日付を保存したいと思いますUTC
。
そこで、JodaDateTimeを使用して次のスニペットを作成しました。
DateTime dateTime = new DateTime(DateTimeZone.forID(user.getTimezone()));
DateTime todayMidnight = dateTime.toDateMidnight().toDateTime();
// now setting the event start and end time
event.setStartTime(todayMidnight.toDate());
event.setEndTime(todayMidnight.plusDays(1).toDate());
私のサーバーはUTCタイムゾーンで実行されていることに注意してください。
America/New_York
UTC-5なので、開始日はそうなると思います4th Feb 2013 5:0:0
が、私にとっては開始日を次のように表示します。3rd Feb 2013 23:0:0
上記のコードに何か問題がありますか?