java中获取时间,常见的是使用:
System.currentTimeMillis()返回的就是以毫秒表示的当前时间戳。
但是在java.time中有一个类instant也可以获取当前时间戳,更加精确:
Instant now = Instant.now();
System.out.println(now.getEpochSecond()); // 秒
System.out.println(now.toEpochMilli()); // 毫秒
java中获取时间,常见的是使用:
System.currentTimeMillis()返回的就是以毫秒表示的当前时间戳。
但是在java.time中有一个类instant也可以获取当前时间戳,更加精确:
Instant now = Instant.now();
System.out.println(now.getEpochSecond()); // 秒
System.out.println(now.toEpochMilli()); // 毫秒