[常用类]Instant类的使用
生活随笔
收集整理的這篇文章主要介紹了
[常用类]Instant类的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*Instant的使用類似于java.util.Date類*/@Testpublic void test2(){//now():獲取本初子午線對應的標準時間Instant instant = Instant.now();System.out.println(instant);//2022-04-25T05:56:58.562637400Z//添加時間的偏移量OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));System.out.println(offsetDateTime);//2022-04-25T14:04:52.981486300+08:00//toEpochMilli():獲取自1970年1月1日0時0分0秒(UTC)開始的毫秒數 ---> Date類的getTime()long milli = instant.toEpochMilli();System.out.println(milli);//1650867450064//ofEpochMilli():通過給定的毫秒數,獲取Instant實例 ---> Date(long millis)Instant instant1 = Instant.ofEpochMilli(1650867450064L);System.out.println(instant1);//2022-04-25T06:17:30.064Z}
總結
以上是生活随笔為你收集整理的[常用类]Instant类的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAS用proc means和proc
- 下一篇: 方正飞鸿智能信息平台产品白皮书(四)