java计算时间差的几种方法
1.计算天数差。
[java] view plain copy
String fromDate = simpleFormat.format("2016-05-01 12:00");
String toDate = simpleFormat.format("2016-06-01 12:00");
long from = simpleFormat.parse(fromDate).getTime();
long to = simpleFormat.parse(toDate).getTime();
int days = (int) ((to 悔碧- from)/(1000 * 60 * 60 * 24));
String fromDate = simpleFormat.format("2016-05-01 12:00");
String 数庆toDate = simpleFormat.format("2016-05-01 14:00");
long from = simpleFormat.parse(fromDate).getTime();
long to = simpleFormat.parse(toDate).getTime();
int hours = (int) ((to - from)/(1000 * 60 * 60));
String fromDate = simpleFormat.format("2016-05-01 12:00");
String toDate = simpleFormat.format("2016-05-01 12:50");
long from = simpleFormat.parse(fromDate).getTime();
long to = simpleFormat.parse(toDate).getTime();
int minutes = (int) ((to - from)/(1000 * 碧毕举60));
2.计算小时差
[java] view plain copy
3.计算分钟差:
[java] view plain copy