ZonedDateTime
を SQL に変換Timestamp
し、タイムゾーン情報を保持するにはどうすればよいですか? UTC ゾーン時刻を取得して に変換してからTimestamp
元に戻そうとしていますが、 に変換するとTimestamp
タイム ゾーン情報が失わTimestamp
れ、ローカル タイム ゾーンを使用して が作成されます。
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
ZonedDateTime zdtUTC = ZonedDateTime.now(ZoneId.of("UTC"));
ZonedDateTime zdtNY = zdtUTC.withZoneSameInstant(ZoneId.of("America/New_York"));
ZonedDateTime zdtAZ = zdtUTC.withZoneSameInstant(ZoneId.of("America/Phoenix"));
ZonedDateTime zdtUK = zdtUTC.withZoneSameInstant(ZoneId.of("Europe/London"));
System.out.println(formatter.format(zdtUTC) + " in UTC zone");
System.out.println(formatter.format(zdtNY) + " in New York, NY");
System.out.println(formatter.format(zdtAZ) + " in Phoenix, AZ");
System.out.println(formatter.format(zdtUK) + " in London, UK");
Timestamp timestamp = Timestamp.from(zdtUTC.toInstant());
LocalDateTime converted = timestamp.toLocalDateTime();
ZonedDateTime convertedZdt = ZonedDateTime.of(converted, ZoneId.of("UTC"));
System.out.println(timestamp);
System.out.println(formatter.format(convertedZdt) + " in UTC zone");
}
06:33 PM in UTC zone
02:33 PM in New York, NY
11:33 AM in Phoenix, AZ
07:33 PM in London, UK
2017-05-07 14:33:06.745
02:33 PM in UTC zone
Timestamp
レコードが正しいタイム ゾーン情報を使用していることを確認するにはどうすればよいですか?