Java将毫秒转成时分秒

代码

public static void main(String[] args) {
		Date start = new Date();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		Date end = new Date();
		
		long interval = DateFormat.printSplitTime("流程A", start, end);//毫秒数
		System.out.println("耗时==" + interval);
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//初始化Formatter的转换格式。
		formatter.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
		String hms = formatter.format(interval);
		System.out.println("耗时==" + hms);
	}
// 比较时间间隔描述
    public static long printSplitTime(String cmd, Date start, Date end) {
        long interval = (end.getTime() - start.getTime());
        //System.out.println("接口耗时:" + interval + "毫秒");
        return interval;
    }

输出:

耗时==00:00:03

你可能感兴趣的:(java)