importorg.apache.commons.lang3.StringUtils;importorg.apache.commons.lang3.time.FastDateFormat;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importjava.lang.management.ManagementFactory;importjava.text.ParseException;importjava.text.ParsePosition;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;/*** 日期处理*/
public class DateUtils extendsorg.apache.commons.lang3.time.DateUtils {private final static Logger logger = LoggerFactory.getLogger(DateUtils.class);private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH","yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM/dd HH", "yyyy/MM","yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM.dd HH", "yyyy.MM", "yyyy年MM月dd日","yyyy年MM月dd日 HH时mm分ss秒", "yyyy年MM月dd日 HH时mm分", "yyyy年MM月dd日 HH时", "yyyy年MM月", "yyyy"};/*** 获取
* 从今天往前beforeDay天到明天凌晨的时间范围,集合范围: [开始时间, 结束时间)
*@return
*/
public static Date[] getTodayDateRange(intbeforeDay) {
Date startDate= DateUtils.truncate(newDate(), Calendar.DATE);
Date endDate= DateUtils.addDays(startDate, 1);if (beforeDay > 0) {
startDate= DateUtils.addDays(startDate, -beforeDay);
}return newDate[] {startDate, endDate};
}/*** 获取
* 从今天往前beforeDay天到明天凌晨的时间范围,集合范围: [开始时间, 结束时间)
*@return
*/
public static String[] getTodayDateRangeStr(intbeforeDay) {
Date startDate= DateUtils.truncate(newDate(), Calendar.DATE);
Date endDate= DateUtils.addDays(startDate, 1);if (beforeDay > 0) {
startDate= DateUtils.addDays(startDate, -beforeDay);
}
String startDateStr= formatDate(startDate, parsePatterns[1]);
String endDateStr= formatDate(endDate, parsePatterns[1]);return newString[] {startDateStr, endDateStr};
}/*** 获取
* 从今天往前beforeDay天到明天凌晨的时间范围,集合范围: [开始时间, 结束时间)
*@return
*/
public static String[] getTodayDateRangeStr0(intbeforeDay) {
Date[] dates=getTodayDateRange(beforeDay);
String star