`

Java耗时计算方法摘要

阅读更多
package com.happy.sqlite.test;

import java.util.Calendar;

public class LostTime {
	@SuppressWarnings("static-access")
	public static void main(String[] args) {
		long t1 = System.currentTimeMillis(); // 排序前取得当前时间

		try {
			Thread.currentThread().sleep(3160);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		long t2 = System.currentTimeMillis(); // 排序后取得当前时间

		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(t2 - t1);

		System.out.println("耗时: " + c.get(Calendar.MINUTE) + "分 "
				+ c.get(Calendar.SECOND) + "秒 " + c.get(Calendar.MILLISECOND)
				+ " 毫秒");
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics