public static String getDateTimePoor( Date startDate ,Date endDate ) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - startDate.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}
public static String getDatePoor( Date startDate ,Date endDate ) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ns = 1000 ;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - startDate.getTime();
// 计算差多少天
//long day = diff / nd;
// 计算差多少小时
long hour = diff / nh;
// 计算差多少分钟
long min = diff % nh / nm;
// 计算差多少秒//输出结果
long sec = diff % nh % nm / ns;
return hour + "时" + min + "分"+ sec + "秒";//17时20分32秒
}
public static void main(String[] args) {
Date date1 = parseYyyyMMddHHmmss("2020-11-13 15:18:15");
Date date2 = parseYyyyMMddHHmmss("2020-11-14 16:19:16");
String datePoor = getDatePoor(date1, date2);
System.out.println();
}
还没有评论,来说两句吧...