從即時值獲取瞬時秒的 Java 程式


建立瞬時值並獲取 1970-01-01T00:00:00Z 曆元以來的時間,以毫秒為單位傳入引數。這使用 ofEpochMilli() 完成

Instant instant = Instant.ofEpochMilli(342627282920l);

現在從瞬時值獲取瞬時秒

instant.getEpochSecond();

示例

import java.time.Instant;
public class Demo {
   public static void main(String[] args) {
      Instant instant = Instant.ofEpochMilli(342627282920l);
      long res = instant.getEpochSecond();
      System.out.println(res);
   }
}

輸出

342627282

更新於: 2019 年 7 月 30 日

193 次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.