获取几天几小时几分钟之前的时间
SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sim2=new SimpleDateFormat("MM-dd");
Date da;
da = sim.parse(a);
Date d = new Date();
// arg2 - d.getTime();
Long gapTime = d.getTime() - da.getTime();
long day = gapTime/(24*3600*1000);
gapTime = gapTime - day*(24*3600*1000);
long hour = gapTime/3600/1000;
gapTime = gapTime - hour*3600*1000;
long min = gapTime/60/1000;
gapTime = gapTime - min*60*1000;
long sec = gapTime/1000;
String dayStr = "";
if(day ==0){
if(hour == 0){
if(min == 0){
dayStr = "刚刚";
}else{
dayStr = min + "分钟之前";
}
}else{
dayStr = hour+"小时之前";
}
}
else if(day==1){
dayStr = "昨天"+da.getHours()+":"+da.getMinutes();
}
else if(day ==2 ){
dayStr = "前天"+da.getHours()+":"+da.getMinutes();
}else{
dayStr = sim2.format(da);
}
return dayStr;
获取几天几小时几分钟之前的时间
最新推荐文章于 2022-04-11 19:21:41 发布