//获取当前时间距离1970-01-01 00:00:00 的毫秒数
long start = System.currentTimeMillis();
//其他代码
//获取当前时间距离1970-01-01 00:00:00 的毫秒数
long end = System.currentTimeMillis();
//利用end与start的差计算Java代码运行时间
System.out.println("所花费的时间为:" + (end - start));
System.currentTimeMillis()返回值:
当前时间与UTC 1970年1月1日0:00之间的差(以毫秒为单位)。