Java中计算时间差的小问题

<<span style="white-space:pre">		</span>/*Calendar rightNow;
		 rightNow = Calendar.getInstance();
		 long start = rightNow1.getTimeInMillis();*/
		  long start = System.currentTimeMillis();	
		for(Integer i : collection){
			System.out.println(i);
		}
		long end = System.currentTimeMillis();
<<span style="white-space:pre">		</span>/*rightNow = Calendar.getInstance();
		long end = rightNow2.getTimeInMillis();*/
System.out.println((end - start)/1000f);



用Calendar跟System计算时间差会有所不同,Calendar计算出来的时间差总是比System的长,这应该是两个的设计不同,以后计算时间差优先使用System
posted @ 2015-04-21 22:22  awenzero  阅读(209)  评论(0编辑  收藏  举报