Instant时间戳类
(一)含义:从1970-01-01 00:00:00到当前时间的毫秒值
(二)常用的方法:
now():
获取当前的时间,获取的是当前的美国时间,和处于东八区的我们相差八个小时。
Instant ins=Instant.now();
System.out.println(ins);
atOffset():
设置偏移量例如:
OffsetDateTime time=ins.atOffset(ZoneOffset.ofHours(8));
System.out.println(time);
atZone()
获取系统默认时区时间,参数为一个时区的编号,可以通过时区编号类获取出来
还可以通过Zoneld.systemDefault()来获取本地的默认时区ID
ZonedDateTime zoneDateTime=ins.atZone(Zoneld.systemDefault());
System.out.println(zonedDateTime);
get系列的方法
getEpochSecond():获取从1970-01-01 00:00:00到当前时间的秒值
getNano():把获取到的当前时间的描述换算成纳秒
ofEpochSecond()方法:在计算机元年(1970-01-01 00:00:00)的基础上增加秒数