获取当前时间所在凌晨和23:59:59

/**
     * 凌晨
     * @param date
     * @flag 0 返回yyyy-MM-dd 00:00:00日期
* 1 返回yyyy-MM-dd 23:59:59日期 * @return */ 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(); }

你可能感兴趣的:(Java,W)