获取超过某个时间一个小时的时间
//返回超过yourTime一个小时的时间
public static String getMoreThanAnHourTime(String yourTime){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String res = "";
Date date;
try {
date = format.parse(yourTime);
//获取传递进来的时间转为时间戳的值
long time=date.getTime();
//把该值加上一个一小时的毫秒数
long anHour = 60*60*1000;
long result = time + anHour;
Date thedate = new Date(result);
res = format.format(thedate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
判断某个时间距离当前时间是否大于一个小时,是返回true,否返回false;
//判断某个时间距离当前时间是否大于一个小时,是返回true,否返回false;
public static boolean isMoreThanAnHour(String yourTime){
boolean value = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
//得到参数时间的时间戳赋值给time
Date date = format.parse(yourTime);
long time=date.getTime();
//再用当前时间的时间戳减去time,大于3600000则返回true,否则返回false
long nowTime = new Date().getTime();
if(nowTime-time>3600000){
value = true;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
}