开始使用免费开始使用

时区转换

您正在跨不同时区跟踪电子产品库存的生产日期。请在两个时区之间转换这些生产日期!

所需的包,如 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);
    }
}
编辑并运行代码