Chuyển đổi múi giờ
Bạn đang theo dõi ngày sản xuất của hàng tồn kho điện tử trên nhiều múi giờ. Hãy chuyển đổi các ngày sản xuất giữa hai múi giờ!
Các gói cần thiết như LocalDate, ZoneId và ZonedDateTime đã được nhập sẵn cho bạn.
Bài tập này là một phần của khóa học
Làm sạch dữ liệu bằng Java
Hướng dẫn bài tập
- Chuyển
datesang múi giờ New York tại thời điểm bắt đầu ngày. - Chuyển thời gian New York
nyTimesang thời gian Los AngeleslaTime.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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);
}
}