---
title: "java计算时间差"
author: "wang286480403"
date: "2014-03-04T16:17:33Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2014-03-04T16:17:33Z"
id: 2025482
url: "https://wang286480403.iteye.com/blog/2025482"
---

```
public static void main(String[] args) {
		long t1 = System.currentTimeMillis(); // 排序前取得当前时间

		try {
			Thread.currentThread().sleep(3160);
		} catch (Exception err) {

		}

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