从 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.