始める無料で始める

タイムゾーンの変換

あなたは電子機器の在庫について、複数のタイムゾーンにまたがる製造日を管理しています。製造日を2つのタイムゾーン間で変換しましょう。

LocalDateZoneIdZonedDateTime などの必要なパッケージはあらかじめインポートされています。

この演習はコースの一部です

Java によるデータクリーニング

コースを見る

演習の手順

  • date をニューヨークのタイムゾーンにおける日付の開始時刻に変換しましょう。
  • ニューヨーク時間の nyTime をロサンゼルス時間の laTime に変換しましょう。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

public class DateStandardizationExample {
    public static void main(String[] args) {
        LocalDate date = LocalDate.parse("2023-01-01");
        
        // Convert the date to the New York time zone at the start of day
        ZonedDateTime nyTime = ____.____(ZoneId.of("America/New_York"));
        // Convert the New York time to Los Angeles time
        ZonedDateTime laTime = ____.____(ZoneId.of("America/Los_Angeles"));
        
        System.out.println("New York time: " + nyTime);
		System.out.println("Los Angeles time: " + laTime);
    }
}
コードを編集して実行