System.currentTimeMillis();产生一个自1970年1月1日0时起到当前的毫秒。
执行时间:
long startTime = System.currentTimeMillis();
......
long endTime = System.currentTimeMillis();
//打印执行时间
Systme.out.print(endTime-startTime);当前时间
Date(System.currentTimeMillis());2038年问题,java下不存在这个问题,不过可以模拟一下
Date date = new Date();
date.setTime((long)Integer.MAX_VALUE*1000);
System.out.println((long)Integer.MAX_VALUE*1000);
System.out.println(System.currentTimeMillis());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
System.out.println(format.format(date.getTime()));
输出:
2147483647000
1455760659980
2038-01-19 11:14:007
本文介绍了Java中使用System.currentTimeMillis()获取当前时间的方法,并演示了如何利用该方法测量代码执行时间。此外,还展示了如何创建Date对象并设置其时间为整型最大值对应的日期,以此来模拟2038年问题。
325

被折叠的 条评论
为什么被折叠?



