当前位置:科普知识站>IT科技>

instant|java

IT科技 阅读(2.33W)

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

instant java是什么,让我们一起了解一下?

instant表示时间线上的一点,时间线上有三个重要的点:最大值点、最小值点、原点(时间不知道有没有尽头)。在Java世界,时间线的末端分别是Instant.MAX和Instant.MIN;时间线的原点是Instant.EPOCH。

(1)时间线上的原点

System.out.println(Instant.EPOCH);

结果:1970-01-01T00:00:00Z

(2)时间线的最大值

System.out.println(Instant.MAX);

结果:+1000000000-12-31T23:59:59.999999999Z

(3)时间线的最小值

System.out.println(Instant.MIN);

结果:-1000000000-01-01T00:00:00Z

instant java

那么时间点的构造是怎样的?

当前时间点

Instant now = Instant.now();System.out.println(now);System.out.println(now.getEpochSecond());System.out.println(now.getNano());System.out.println(now.toEpochMilli());

结果:

2019-04-18T08:04:29.633Z15555746696330000001555574669633