对于 ZonedDateTime 的测试
ZonedDateTime和ZoneId类是指定时区的时间,通常用ZoneId类来指定时区,然后构ZoneDateTime对象
ZoneId提供了许多的时区,这些时区以映射的方式被存储在 ZoneId的 SHORT_IDS中
java11 java.time包的官方文档https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class TestZonedDateTime {
public static void main(String[] args){
ZoneId zoneid = ZoneId.systemDefault(); //获取的是系统默认的时区
//第一种构造方式
ZoneId zone = ZoneId.of(ZoneId.SHORT_IDS.get("AET")); //获取澳大利亚悉尼的时区
ZonedDateTime xn = ZonedDateTime.now(zone);
System.out.println(xn);
//第二种构造方式
ZoneId zone2 = ZoneId.of(ZoneId.SHORT_IDS.get("CST")); //芝加哥的时区
LocalDateTime ldt = LocalDateTime.of(2013,12,3,5,31);
ZonedDateTime zjg = ZonedDateTime.of(ldt,zone2);
System.out.println(zjg);
//还可以单独创建 LocalDate 和LocaTime来指定时间,这里就不写了
//同样的 , ZonedDateTime也支持与LocalDateTime一样的方法
System.out.println(zjg.withYear(2200).withMonth(12).withDayOfMonth(3).withDayOfYear(300));
}
}
这里是对于 LocalDate 的测试:
https://blog.csdn.net/qq_42394457/article/details/85086381