方法一:
public static void startRun(){
//获取本次的时间,并输出。Date day1=new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
System.out.print("程序开始运行时刻:");
System.out.println(df.format(day1));
}
方法二:
long startTime=System.currentTimeMillis();
long endTime=System.currentTimeMillis();
System.out.println("本次采集数据共用时:"+(endTime-startTime)+"毫秒");

本文介绍了两种在Java中记录时间的方法。第一种使用Date和SimpleDateFormat类来获取并格式化当前时间,第二种则利用System.currentTimeMillis()来计算程序运行的耗时。

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



