import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author libin
* @date 2018/12/14 15:12:13
*/
public class Demo {
public static void main(String[] args) {
// 计算时间差
System.out.println(CalTime("15:05", "14:35"));
}
// 计算两个时间差
public static long CalTime(String time1, String time2) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
long minutes = 0l;
try {
Date d1 = df.parse(time1);
Date d2 = df.parse(time2);
long diff = d1.getTime() - d2.getTime();// 这样得到的差值是微秒级别
minutes = diff / (1000 * 60);
} catch (Exception e) {
}
return minutes;
}
}
点击查看结果
30
原文地址:https://www.cnblogs.com/hglibin/p/10119645.html
时间: 2024-10-06 16:50:02