Mengonversi zona waktu
Anda sedang melacak tanggal pembuatan inventaris elektronik Anda di berbagai zona waktu. Konversikan tanggal pembuatan tersebut di antara dua zona waktu!
Pustaka yang diperlukan seperti LocalDate, ZoneId, dan ZonedDateTime telah diimpor untuk Anda.
Latihan ini merupakan bagian dari kursus
Pembersihan Data di Java
Instruksi latihan
- Konversikan
dateke zona waktu New York pada awal hari. - Konversikan waktu New York
nyTimeke waktu Los AngeleslaTime.
Latihan interaktif langsung praktik
Cobalah latihan ini dengan melengkapi kode contoh ini.
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);
}
}