Instant类
-
类似于java.utils.Date
//now获取的是本初子午线的时间 Instant now = Instant.now(); System.out.println(now); //2020-09-11T13:32:36.046Z 本初子午线时间 //添加时间的偏移量 OffsetDateTime offsetDateTime = now.atOffset(ZoneOffset.ofHours(8)); System.out.println(offsetDateTime); //获取瞬时点对应的毫秒数 long l = now.toEpochMilli(); System.out.println(l); //ofEpochMilli():通过给定的毫秒数,获取Instant实例 Instant instant = Instant.ofEpochMilli(1599831484077L); System.out.println(instant);