Java 程式從 Instant 獲取毫秒


建立一個 Instant,並使用 1970-01-01T00:00:00Z 以紀元作為引數傳遞的毫秒來獲取 Instant。這是透過 ofEpochMilli() 完成的

Instant instant = Instant.ofEpochMilli(342627282920l);

現在,從 Instant 獲取紀元毫秒

instant. toEpochMilli();

示例

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

輸出

1262347200000

更新時間:2019 年 7 月 30 日

190 次瀏覽

開始你的 職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.