您的位置:首页 > 移动开发 > Android开发

android 判断时间是否已过期

2017-12-09 11:09 1146 查看
public static boolean IsToday(String day) throws ParseException {
// 当前的时刻
Calendar pre = Calendar.getInstance();
Date predate = new Date(System.currentTimeMillis());
pre.setTime(predate);

// 设定的时刻
Calendar cal = Calendar.getInstance();
Date date = sdf.parse(day);
cal.setTime(date);

if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) {
int diffDay = cal.get(Calendar.DAY_OF_YEAR) - pre.get(Calendar.DAY_OF_YEAR);
int diffHour = cal.get(Calendar.HOUR_OF_DAY) - pre.get(Calendar.HOUR_OF_DAY);
int diffMin = cal.get(Calendar.MINUTE) - pre.get(Calendar.MINUTE);
if (diffDay == 0) {
if (diffHour == 0) {
if (diffMin >= 0) {
return true;
}
} else if (diffHour > 0) {
return true;
}
} else if (diffDay > 0) {
return true;
}
} else if (cal.get(Calendar.YEAR) > (pre.get(Calendar.YEAR))) {
return true;
}
return false;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
cur_time.setText(sdf.format(new Date()));// 开会时间
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: