/* Instant的使用 类似于Java.util.Date类 */ @Test public void test2(){ //now():对应本初子午线对应的标准时间 Instant instant = Instant.now(); System.out.println(instant); //添加时间的偏移量 OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8)); System.out.println(offsetDateTime); //toEpochMilli:获取对应的毫秒数-->Date.getTime() long milli = instant.toEpochMilli(); System.out.println(milli); //ofEpochMilli:通过给定的毫秒数,获取Instant实例--->Date(long millis) Instant instant1 = Instant.ofEpochMilli(1645728380); System.out.println(instant1); }