使用 Java 日期和时间转换字符显示自 Epoch 以来的毫秒
若要显示自 Epoch 来的毫秒,请使用“Q”日期和时间转换字符。
System.out.printf("
Milliseconds since epoch = %TQ", d);
上面将显示自来的毫秒。
1970-01-01 00:00:00 GMT
示例
import java.util.Date; public class Demo { public static void main(String[] args) { Date d = new Date(); System.out.printf("Nanoseconds = %tN
", d); System.out.printf("Seconds since epoch = %ts", d); System.out.printf("
Milliseconds since epoch = %TQ", d); } }
输出
Nanoseconds = 050000000 Seconds since epoch = 1543241478 Milliseconds since epoch = 1543241478050
广告