An instantaneous point on the time-line. 中文描述就是Instant表示高精度时间戳。
java.time.Instant 类是在 Java 8 中引入,是对原有日期时间处理API(主要包括 java.util.Date、java.util.Calendar 和 java.sql.Timestamp 等类)的重大改进和现代化升级。
2024-07-30T14:50:13.0489927+08:00[Asia/Shanghai] 执行如下代码
Instant.now()); // 2024-07-30T06:50:13.053659800Z 【时间戳显示成0时区时间格式】
Instant.now().atZone(ZoneOffset.UTC)); // 2024-07-30T06:50:13.053819900Z 【时间戳显示成指定时区时间格式】
Instant.now().atZone(ZoneId.of("Asia/Tokyo"))); // 2024-07-30T15:50:13.053819900+09:00[Asia/Tokyo] 【时间戳显示成指定时区时间格式】
System.currentTimeMillis()); // 1722322213053
Instant.now().toEpochMilli()); // 1722322213053
Instant.now().getEpochSecond()); // 1722322213
Instant.now().getNano()); // 53819900
Instant.ofEpochMilli(1562501898000L)); //2019-07-07T12:18:18Z 【0时区时间】
Instant.ofEpochMilli(1562501898888L)); //2019-07-07T12:18:18.888Z 【0时区时间】
Instant.ofEpochSecond(1562501898)); //2019-07-07T12:18:18Z 【0时区时间】
Instant.ofEpochSecond(1562501898,888)); //2019-07-07T12:18:18.000000888Z 【0时区时间】
Instant.parse("2019-07-07T20:18:18.000000888Z")); //2019-07-07T20:18:18.000000888Z 【视String为0时区时间去类型转换】
Instant.parse("2019-07-07T20:18:18Z")); //2019-07-07T20:18:18Z 【视String为0时区时间去类型转换】
ZonedDateTime ZONED_DATE_TIME = ZonedDateTime.of(2019, 7, 7, 20, 18, 18, 888, ZoneId.of("Asia/Tokyo"));
OffsetDateTime OFFSET_DATE_TIME = OffsetDateTime.of(2019, 7, 7, 20, 18, 18, 888, ZoneOffset.ofHours(9));
LocalDateTime LOCAL_DATE_TIME = LocalDateTime.of(2019, 7, 7, 20, 18, 18, 888);
Date DATE = new Date(1562501898888L);// Sun Jul 07 20:18:18 CST 2019
ZONED_DATE_TIME.toInstant()); //2019-07-07T11:18:18.000000888Z 【0时区】
OFFSET_DATE_TIME.toInstant()); //2019-07-07T11:18:18.000000888Z 【0时区】
LOCAL_DATE_TIME.toInstant(ZoneOffset.ofHours(8))); //2019-07-07T12:18:18.000000888Z 【0时区】
LOCAL_DATE_TIME.toInstant(ZoneOffset.UTC)); //2019-07-07T20:18:18.000000888Z 【0时区】
DATE.toInstant()); //2019-07-07T12:18:18.888Z 【0时区】
Instant.MIN);//-1000000000-01-01T00:00:00Z
Instant.MAX);//+1000000000-12-31T23:59:59.999999999Z
Instant.EPOCH);//1970-01-01T00:00:00Z
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。