在本文中,您将学习如何在 Java 中获取以毫秒为单位的当前纪元时间戳。
public class CurrentEpochTimestampExample {
public static void main(String[] args) {
// Get epoch timestamp using System.currentTimeMillis()
long currentTimestamp = System.currentTimeMillis();
System.out.println("Current epoch timestamp in millis: " + currentTimestamp);
}
}
import java.time.Instant;
public class CurrentEpochTimestampExample {
public static void main(String[] args) {
// Get current timestamp using Instant
currentTimestamp = Instant.now().toEpochMilli();
System.out.println("Current epoch timestamp in millis: " + currentTimestamp);
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://www.callicoder.com/how-to-get-current-epoch-timestamp-java/
内容来源于网络,如有侵权,请联系作者删除!