public static Date weeHours(Date date, int flag) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
// 时分秒(毫秒数)
long millisecond = hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000;
// 凌晨00:00:00
cal.setTimeInMillis(cal.getTimeInMillis() - millisecond);
if (flag == 0) {
return cal.getTime();
} else if (flag == 1) {
// 凌晨23:59:59
cal.setTimeInMillis(cal.getTimeInMillis() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
}
return cal.getTime();
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
// 时分秒(毫秒数)
long millisecond = hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000;
// 凌晨00:00:00
cal.setTimeInMillis(cal.getTimeInMillis() - millisecond);
if (flag == 0) {
return cal.getTime();
} else if (flag == 1) {
// 凌晨23:59:59
cal.setTimeInMillis(cal.getTimeInMillis() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
}
return cal.getTime();
}