java获得timestamp的有哪些方法
在Java中,可以通过以下几种方法来获得当前的时间戳(timestamp):
System.currentTimeMillis()
方法获得当前时间的毫秒数:long timestamp = System.currentTimeMillis();
Instant.now().toEpochMilli()
方法获得当前时间的毫秒数:import java.time.Instant;
long timestamp = Instant.now().toEpochMilli();
new Date().getTime()
方法获得当前时间的毫秒数:import java.util.Date;
long timestamp = new Date().getTime();
以上三种方法都可以获得到当前的时间戳,只是使用的类和方法略有区分。
TOP