從 Epoch 秒和毫秒建立 Instant 的 Java 程式


從 Epoch 秒建立 Instant

示例

import java.time.Instant;
public class Demo {
   public static void main(String[] args) {
      Instant instant = Instant.ofEpochSecond(282829279);
      System.out.println(instant);
   }
}

輸出

1978-12-18T11:41:19Z

從 Epoch 毫秒建立 Instant

示例

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

輸出

1978-08-24T17:21:22.728Z

更新於:30-Jul-2019

1 千次+瀏覽

開啟 職業生涯

完成此課程獲得認證

開始
廣告
© . All rights reserved.