instant - java
來源:趣味經驗館 2.25W
<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 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