---
title: "耗时计算的部分代码"
author: "easy0917"
date: "2012-08-20T06:47:17Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-08-20T06:47:17Z"
id: 1637694
url: "https://easy0917.iteye.com/blog/1637694"
---

```
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)
				+ " 毫秒");
	}
}
```