java生成时间戳的方法有哪些
Java中生成时间戳的方法有以下几种:
使用System.currentTimeMillis()方法:
long timestamp = System.currentTimeMillis();
使用Date类:
Date date = new Date();
long timestamp = date.getTime();
使用Calendar类:
Calendar calendar = Calendar.getInstance();
long timestamp = calendar.getTimeInMillis();
使用Instant类(Java 8及以上版本):
Instant instant = Instant.now();
long timestamp = instant.toEpochMilli();
以上方法都可以获得当前时间的毫秒级时间戳。
阅读剩余
THE END