java相差小时数

public static String getTime(Date date){
StringBuffer time = new StringBuffer();
Date date2 = new Date();
long temp = date2.getTime() - date.getTime();
long days = temp / 1000 / 3600/24; //相差小时数
if(days>0){
time.append(days+"天");
}
long temp1 = temp % (1000 * 3600*24);
long hours = temp1 / 1000 / 3600; //相差小时数
if(days>0 || hours>0){
time.append(hours+"小时");
}
long temp2 = temp1 % (1000 * 3600);
long mins = temp2 / 1000 / 60; //相差分钟数
time.append(mins + "分钟");
return time.toString();
}
posted @ 2018-02-23 16:58  Birdgeduan  阅读(437)  评论(0编辑  收藏  举报