自带有Java日期和时间转换字符的纪元以来的毫秒数
要显示自纪元以来的毫秒数,请使用“Q”日期和时间转换说明符。
System.out.printf("\nMilliseconds 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\n", d); System.out.printf("Seconds since epoch = %ts", d); System.out.printf("\nMilliseconds since epoch = %TQ", d); } }
输出结果
Nanoseconds = 050000000 Seconds since epoch = 1543241478 Milliseconds since epoch = 1543241478050