package com.cym.utils.cert;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import com.google.common.collect.Maps;

/**
 * @ClassName DateUtils
 * @Description 日期工具类
 * @Author ZhangSan_Plus
 * @Date 2020/5/11 9:53
 * @Version 1.0
 **/
public class DateUtils {
	public final static int FORMAT_DEFAULT = 0;

	/**
	 * 日时字符串格式：长格式（如：年份用4位表示）
	 */
	public final static int FORMAT_LONG = 1;

	/**
	 * 日时字符串格式：短格式（如：年份用2位表示）
	 */
	public final static int FORMAT_SHORT = 2;

	/**
	 * 默认日期字符串格式 "yyyy-MM-dd"
	 */
	public final static String DATE_DEFAULT = "yyyy-MM-dd";
	/**
	 * 日期字符串格式 "yyyy"
	 */
	private final static String DATE_YYYY = "yyyy";
	/**
	 * 日期字符串格式 "mm"
	 */
	private final static String DATE_MM = "mm";
	/**
	 * 日期字符串格式 "dd"
	 */
	private final static String DATE_DD = "dd";
	/**
	 * 日期字符串格式 "yyyyMM"
	 */
	public final static String DATE_YYYYMM = "yyyyMM";

	/**
	 * 日期字符串格式 "yyyyMMdd"
	 */
	public final static String DATE_YYYYMMDD = "yyyyMMdd";

	/**
	 * 日期字符串格式 "yyyy-MM"
	 */
	public final static String DATE_YYYY_MM = "yyyy-MM";

	/**
	 * 日期字符串格式 "yyyy-MM-dd"
	 */
	public final static String DATE_YYYY_MM_DD = "yyyy-MM-dd";

	/**
	 * 默认日时字符串格式 "yyyy-MM-dd HH:mm:ss"
	 */
	public final static String DATETIME_DEFAULT = "yyyy-MM-dd HH:mm:ss";

	/**
	 * 日时字符串格式 "yyyy-MM-dd HH:mm"
	 */
	public final static String DATETIME_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";

	/**
	 * 日时字符串格式 "yyyy-MM-dd HH:mm:ss"
	 */
	public final static String DATETIME_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

	/**
	 * 日时字符串格式 "yyyy-MM-dd HH:mm:ss.SSS"
	 */
	public final static String DATETIME_YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS";

	/**
	 * 默认时间字符串格式 "HH:mm:ss"
	 */
	public final static String TIME_DEFAULT = "HH:mm:ss";

	/**
	 * 默认时间字符串格式 "HH:mm"
	 */
	public final static String TIME_HH_MM = "HH:mm";

	/**
	 * 默认时间字符串格式 "HH:mm:ss"
	 */
	public final static String TIME_HH_MM_SS = "HH:mm:ss";
	/**
	 * 年
	 */
	public static final long YEAR_NUMBER = 365;
	/**
	 * 分
	 */
	public static final long MINUTE_TTL = 60 * 1000L;
	/**
	 * 时
	 */
	public static final long HOURS_TTL = 60 * 60 * 1000L;
	/**
	 * 半天
	 */
	public static final long HALF_DAY_TTL = 12 * 60 * 60 * 1000L;
	/**
	 * 天
	 */
	public static final long DAY_TTL = 24 * 60 * 60L * 1000L;
	/**
	 * 月
	 */
	public static final long MONTH_TTL = 30 * 24 * 60 * 60 * 1000L;
	public static final String DAY_BEFORE_STR = "天前";
	public static final String HOUR_BEFORE_STR = "小时前";
	public static final String MINUTE_BEFORE_STR = "分钟前";
	public static final String SECONDS_BEFORE_STR = "秒前";
	public static final String TIME_OPERATION_SRT = "TIME_OPERATION";
	public static final String TIME_STRAP_STR = "TIME_STRAP";

	public static Integer getMonth(Integer month) {
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.MONTH, month);
		return c.get(Calendar.YEAR);
	}

	/**
	 * 将字符串转换成日期
	 *
	 * @param str
	 * @return java.util.Date
	 * @author ZhangSan_Plus
	 * @description //
	 * @date 18:46 2022/2/28
	 **/
	public static Date getDateToStr(String str) {
		SimpleDateFormat format = new SimpleDateFormat(DATE_YYYY_MM_DD);
		Date r = null;
		try {
			r = format.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return r;
	}

	/**
	 * 时间计算
	 *
	 * @param day
	 * @return
	 */
	public static String countData(String day) {
		SimpleDateFormat format = new SimpleDateFormat(DATE_YYYY_MM_DD);
		Calendar c = Calendar.getInstance();
		c.add(Calendar.YEAR, -Integer.parseInt(day));
		Date start = c.getTime();
		String startDay = format.format(start);
		return startDay;
	}

	/**
	 * 获取指定日期前一天日期
	 *
	 * @param specifiedDay
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:04 2021/4/30
	 **/
	public static String getSpecifiedDayBefore(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat(DATE_YYYY_MM_DD).parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day - 1);

		String dayBefore = new SimpleDateFormat(DATE_YYYY_MM_DD).format(c.getTime());
		return dayBefore;
	}

	public static String ToSevenDate(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat(DATE_YYYY_MM_DD).parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day - 7);

		String dayBefore = new SimpleDateFormat(DATE_YYYY_MM_DD).format(c.getTime());
		return dayBefore;
	}

	public static String ToThirtyDate(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat(DATE_YYYY_MM_DD).parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day - 30);

		String dayBefore = new SimpleDateFormat(DATE_YYYY_MM_DD).format(c.getTime());
		return dayBefore;
	}

	/**
	 * 获取指定日期后一天的数据
	 *
	 * @param
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:35 2021/4/30
	 **/
	public static String getSpecifiedDayAfter(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat(DATE_YYYY_MM_DD).parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day + 1);

		String dayAfter = new SimpleDateFormat(DATE_YYYY_MM_DD).format(c.getTime());
		return dayAfter;
	}

	/**
	 * Calculate the difference between two time
	 *
	 * @param startDate
	 * @param endDate
	 * @return int(两个时间相差的天数)
	 * @throws
	 * @Author ZhangSan_Plus
	 */
	public static int daysBetween(Date startDate, Date endDate) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		long sTime = calendar.getTimeInMillis();
		calendar.setTime(endDate);
		long endTime = calendar.getTimeInMillis();
		long between_days = (endTime - sTime) / DAY_TTL;
		return Integer.parseInt(String.valueOf(between_days));
	}

	/**
	 * 计算时间差距年月,并计算信用分
	 *
	 * @param fromDate
	 * @param toDate
	 * @return java.util.Map<java.lang.String, java.lang.Object>
	 * @author ZhangSan_Plus
	 * @description //
	 * @date 9:34 2021/12/17
	 **/
	public static Map<String, Object> dayCompare(Date fromDate, Date toDate, Integer type) {
		Map<String, Object> maps = Maps.newHashMap();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(fromDate);
		int startY = calendar.get(Calendar.YEAR);
		int startM = calendar.get(Calendar.MONTH);
		Calendar calendar1 = Calendar.getInstance();
		calendar1.setTime(toDate);
		int endY = calendar1.get(Calendar.YEAR);
		int endM = calendar1.get(Calendar.MONTH);
		int mos = (endY - startY) * 12 + (endM - startM);
		int lyear = mos / 12;
		int lmonth = mos % 12;
		maps.put("year", lyear);
		maps.put("month", lmonth);
		if (type == 1) {
			if (lyear != 0) {
				if (lmonth == 0) {
					maps.put("cred", lyear + "年");
					maps.put("sources", (lyear * 12 * 10 + lmonth * 10));
				} else {
					maps.put("cred", lyear + "年" + lmonth + "个月");
					maps.put("sources", (lyear * 12 * 10 + lmonth * 10));
				}
			} else {
				if (lmonth == 0) {
					lmonth = lmonth + 1;
				}
				maps.put("cred", lmonth + "个月");
				maps.put("sources", (lmonth * 10));
			}
		} else {
			maps.put("cred", lyear + 1 + "年");
		}
		return maps;
	}

	/**
	 * 时间戳差值计算
	 *
	 * @param
	 * @return java.lang.String
	 * @throws
	 * @author liyangshuai
	 * @date 15:40 2021/6/9
	 **/
	public static String getDistanceTime(long time1, long time2) {
		long diff;
		if (time1 < time2) {
			diff = time2 - time1;
		} else {
			diff = time1 - time2;
		}
		long day = diff / (DAY_TTL);
		long hour = (diff / (60 * 60 * 1000) - day * 24);
		long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
		long sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		if (day != 0) {
			if (day > 10) {
				return sdf.format(new Date(time2));
			}
			return day + "天前";
		}
		if (hour != 0) {
			return hour + HOUR_BEFORE_STR;
		}
		if (min != 0) {
			return min + MINUTE_BEFORE_STR;
		}
		if (sec != 0) {
			return sec + SECONDS_BEFORE_STR;
		}
		return "";
	}

	private static SimpleDateFormat sdf = new SimpleDateFormat(DATE_YYYY_MM_DD);
	private static SimpleDateFormat HMSSdf = new SimpleDateFormat(DATETIME_YYYY_MM_DD_HH_MM_SS);

	public static Map<String, Object> getDateUnixStr(String dateStr) throws ParseException {
		Map<String, Object> map = Maps.newHashMap();
		long diff;
		long time1 = System.currentTimeMillis();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(HMSSdf.parse(dateStr));
		calendar.add(Calendar.DAY_OF_MONTH, 0);
		long time2 = calendar.getTime().getTime();
		map.put(TIME_STRAP_STR, time2);
		if (time1 < time2) {
			diff = time2 - time1;
		} else {
			diff = time1 - time2;
		}
		long day = diff / (DAY_TTL);
		long hour = (diff / (60 * 60 * 1000) - day * 24);
		long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
		long sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		if (day != 0) {
			map.put(TIME_OPERATION_SRT, String.valueOf(sdf.format(new Date(time2))));
			return map;
		}
		if (hour != 0) {
			map.put(TIME_OPERATION_SRT, hour + HOUR_BEFORE_STR);
			return map;
		}
		if (min != 0) {
			map.put(TIME_OPERATION_SRT, min + MINUTE_BEFORE_STR);
			return map;
		}
		if (sec != 0) {
			map.put(TIME_OPERATION_SRT, sec + SECONDS_BEFORE_STR);
			return map;
		}
		return null;
	}

	/**
	 * Gets the current system time
	 *
	 * @param
	 * @return java.util.Date
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:36 2021/4/30
	 **/
	public static Date getNewDate() {
		SimpleDateFormat df = new SimpleDateFormat(DATETIME_YYYY_MM_DD_HH_MM_SS);
		Date newDate = null;
		try {
			newDate = df.parse(df.format(new Date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return newDate;
	}

	/**
	 * Get the date string format by default（yyyy-MM-dd） pattern can "yyyy-MM-dd"
	 * "HH:mm:ss" "E"
	 *
	 * @param date
	 * @param pattern
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:37 2021/4/30
	 **/
	public static String formatDate(Date date, Object... pattern) {
		String formatDate = null;
		if (pattern != null && pattern.length > 0) {
			formatDate = DateFormatUtils.format(date, pattern[0].toString());
		} else {
			formatDate = DateFormatUtils.format(date, DATE_YYYY_MM_DD);
		}
		return formatDate;
	}

	/**
	 * 根据指定的时间催获取时间
	 *
	 * @param dateUnix
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 11:00 2021/7/5
	 **/
	public static String getDateByDateUnix(Long dateUnix) {
		return sdf.format(new Date(dateUnix * 1000));
	}

	/**
	 * 获取指定日期 指定天数的字符串值
	 *
	 * @param date
	 * @param days
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:39 2021/5/6
	 **/
	public static String getDisposeDate(Date date, Integer days) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, days);
		return DateFormatUtils.format(calendar.getTime(), DATE_YYYY_MM_DD);
	}

	public static Date getDisposeToDate(Date date, Integer days) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, days);
		return calendar.getTime();
	}

	public static Date getDisposeToYear(Date date, Integer year) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.YEAR, year);
		return calendar.getTime();
	}

	/**
	 * 获取指定时间的时间戳
	 * <p>
	 * (int) (System.currentTimeMillis() / 1000) https://tool.lu/timestamp/
	 *
	 * </p>
	 *
	 * @param
	 * @return long
	 * @throws
	 * @author liyangshuai
	 * @date 15:28 2021/6/9
	 **/
	public static long getUnixNum(Date date, Integer days) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, days);
		long time = calendar.getTime().getTime() / 1000;
		return time;
	}

	/**
	 * get the current year str format（yyyy）
	 *
	 * @param
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:49 2021/4/30
	 **/
	public static String getYear() {
		return formatDate(new Date(), DATE_YYYY);
	}

	/**
	 * get the current month format（MM）
	 *
	 * @param
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:52 2021/4/30
	 **/
	public static String getMonth() {
		return formatDate(new Date(), DATE_MM);
	}

	/**
	 * get the current day format（dd）
	 *
	 * @param
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:52 2021/4/30
	 **/
	public static String getDay() {
		return formatDate(new Date(), DATE_DD);
	}

	/**
	 * 获取当前时间的字符串形式（例如；"201806291135"）
	 *
	 * @return 年月日时分
	 */
	public static String getDateToString() {
		Calendar c = Calendar.getInstance();
		return getYear() + getMonth() + getDay() + c.get(Calendar.HOUR_OF_DAY) + c.get(Calendar.MINUTE);
	}

	/**
	 * Get the number of years in the past
	 *
	 * @param date
	 * @return java.lang.Long
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:37 2021/4/30
	 **/
	public static Long pastYear(Date date) {
		return date == null ? null : pastDays(date) / YEAR_NUMBER;
	}

	/**
	 * Get the number of days in the past
	 *
	 * @param date
	 * @return long
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:38 2021/4/30
	 **/
	public static long pastDays(Date date) {
		long t = System.currentTimeMillis() - date.getTime();
		return t / DAY_TTL;
	}

	/**
	 * 获取过去的小时
	 *
	 * @param date
	 * @return long
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:38 2021/4/30
	 **/
	public static long pastHour(Date date) {
		long t = System.currentTimeMillis() - date.getTime();
		return t / HOURS_TTL;
	}

	/**
	 * return To date the number of days in the past
	 *
	 * @param date
	 * @return long
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:39 2021/4/30
	 **/
	public static long pastMinutes(Date date) {
		long t = System.currentTimeMillis() - date.getTime();
		return t / MINUTE_TTL;
	}

	/**
	 * Get the number of days between two dates
	 *
	 * @param before
	 * @param after
	 * @return double
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 17:39 2021/4/30
	 **/
	public static double getDistanceOfTwoDate(Date before, Date after) {
		long beforeTime = before.getTime();
		long afterTime = after.getTime();
		return (afterTime - beforeTime) / DAY_TTL;
	}

	/**
	 * 通过身份证号码获取出生日期、性别、年齡
	 *
	 * @param certificateNo
	 * @return 返回的出生日期格式：1990-01-01 性别格式：2-女，1-男
	 */
	public static Map<String, String> getBirAgeSex(String certificateNo) {
		String birthday = "";
		String age = "";
		String sexCode = "";
		int year = Calendar.getInstance().get(Calendar.YEAR);
		char[] number = certificateNo.toCharArray();
		boolean flag = true;
		if (number.length == 15) {
			for (int x = 0; x < number.length; x++) {
				if (!flag) {
					return new HashMap<>(10);
				}
				flag = Character.isDigit(number[x]);
			}
		} else if (number.length == 18) {
			for (int x = 0; x < number.length - 1; x++) {
				if (!flag) {
					return new HashMap<>(10);
				}
				flag = Character.isDigit(number[x]);

			}
		}
		if (flag && certificateNo.length() == 15) {
			birthday = "19" + certificateNo.substring(6, 8) + "-" + certificateNo.substring(8, 10) + "-" + certificateNo.substring(10, 12);
			sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "2" : "1";
			age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + "";
		} else {
			birthday = certificateNo.substring(6, 10) + "-" + certificateNo.substring(10, 12) + "-" + certificateNo.substring(12, 14);
			sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "2" : "1";
			age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + "";
		}
		Map<String, String> map = new HashMap<>();
		map.put("birthday", birthday);
		map.put("age", age);
		map.put("sexCode", sexCode);
		return map;
	}

	/**
	 * 根据身份证的号码算出当前身份证持有者的年龄 18位身份证
	 *
	 * @return
	 * @throws Exception
	 * @author ZhangSan_Plus
	 */
	public static int getCarAge(String birthday) {
		// 得到年份
		String year = birthday.substring(0, 4);
		// 得到月份
		String yue = birthday.substring(4, 6);
		// 得到当前的系统时间
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat(DATE_YYYY_MM_DD);
		// 当前年份
		String fYear = format.format(date).substring(0, 4);
		// 月份
		String fYue = format.format(date).substring(5, 7);
		int age = 0;
		// 当前月份大于用户出身的月份表示已过生
		if (Integer.parseInt(yue) <= Integer.parseInt(fYue)) {
			age = Integer.parseInt(fYear) - Integer.parseInt(year) + 1;
		} else {// 当前用户还没过生
			age = Integer.parseInt(fYear) - Integer.parseInt(year);
		}
		return age;
	}

	/**
	 * 根据身份证获取性别
	 */
	public static String getCarSex(String CardCode) {
		String sex;
		if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {
			// 判断性别
			sex = "2";
		} else {
			sex = "1";
		}
		return sex;
	}

	/**
	 * 根据传入的日历型日期，计算出执行的时间值（精确版）
	 *
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	public static String countExecTimeToString_exact(Calendar beginTime, Calendar endTime) {// 计算两个日期类型之间的差值（单位：毫秒）
		Long timeDispersion = endTime.getTimeInMillis() - beginTime.getTimeInMillis();
		String tmpMsg = "耗时: ";
		// 记录时间的数值（几小时、几分、几秒）
		int timeNum = 0;
		// 判断是否足够一小时
		if (timeDispersion >= (HOURS_TTL)) { // 若足够则计算有几小时
			timeNum = (int) (timeDispersion / HOURS_TTL);
			tmpMsg += timeNum + "时";
			timeDispersion = timeDispersion - (timeNum * HOURS_TTL);
		}
		// 判断是否足够一分钟
		if (timeDispersion >= (MINUTE_TTL)) {// 若足够则计算有几分钟
			timeNum = (int) (timeDispersion / MINUTE_TTL);
			tmpMsg += timeNum + "分";
			timeDispersion = timeDispersion - (timeNum * MINUTE_TTL);
		}
		// 判断是否足够一秒
		if (timeDispersion >= 1000) {
			timeNum = (int) (timeDispersion / 1000);
			tmpMsg += timeNum + "秒";
			timeDispersion = timeDispersion - timeNum * 1000;
		}
		tmpMsg += timeDispersion + "毫秒";
		return tmpMsg;
	}

	/**
	 * 直接返回毫秒数
	 *
	 * @param beginTime
	 * @param endTime
	 * @return java.lang.Long
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:43 2021/5/6
	 **/
	public static Long countMsDataTime(Calendar beginTime, Calendar endTime) {
		return (endTime.getTimeInMillis() - beginTime.getTimeInMillis());
	}

	/**
	 * 根据传入的long类型日期，计算出执行的时间值（精确版）
	 *
	 * @param beginTime
	 * @param endTime
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:44 2021/5/6
	 **/
	public static String countMsDataTimeToString(Long beginTime, Long endTime) {
		Long timeDispersion = endTime - beginTime;
		String tmpMsg = "耗时: ";
		int timeNum = 0;
		if (timeDispersion >= (HOURS_TTL)) {
			timeNum = (int) (timeDispersion / (HOURS_TTL));
			tmpMsg += timeNum + "时";
			timeDispersion = timeDispersion - (timeNum * HOURS_TTL);
		}
		if (timeDispersion >= (MINUTE_TTL)) {
			timeNum = (int) (timeDispersion / (MINUTE_TTL));
			tmpMsg += timeNum + "分";
			timeDispersion = timeDispersion - (timeNum * MINUTE_TTL);
		}
		if (timeDispersion >= 1000) {
			timeNum = (int) (timeDispersion / 1000);
			tmpMsg += timeNum + "秒";
			timeDispersion = timeDispersion - timeNum * 1000;
		}
		tmpMsg += timeDispersion + "毫秒";
		return tmpMsg;

	}

	/**
	 * 获取指定年度全部月份集合
	 *
	 * @param year
	 * @return java.util.List<java.lang.String>
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:45 2021/5/6
	 **/
	public static List<String> getYearMonthByYear(String year) {
		List<String> monthList = new ArrayList<>();
		for (int i = 1; i <= 12; i++) {
			monthList.add(year + "-" + (i < 10 ? "0" : "") + i);
		}
		return monthList;
	}

	/**
	 * 获取下个月
	 *
	 * @param dateStr
	 * @param format
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:45 2021/5/6
	 **/
	public static String getPreMonth(String dateStr, String format) {
		String preMonth = "";
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date;
		try {
			date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(Calendar.MONTH, 1);
			sdf.format(calendar.getTime());

		} catch (ParseException e) {
			// Auto-generated catch block
			e.printStackTrace();
		}
		return preMonth;
	}

	/**
	 * 获取下个月str
	 *
	 * @param dateStr
	 * @param format
	 * @return java.lang.String
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:46 2021/5/6
	 **/
	public static String getPreMonthFormat(String dateStr, String format) {
		String preMonth = "";
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date;
		try {
			date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(Calendar.MONTH, 1);
			preMonth = sdf.format(calendar.getTime());

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return preMonth;
	}

	/**
	 * 日期比较
	 *
	 * @param
	 * @return boolean
	 * @throws
	 * @author ZhangSan_Plus
	 * @date 14:47 2021/5/6
	 **/
	public static boolean dateSize(String aDate, String bDate, SimpleDateFormat format) {
		boolean str = false;
		try {
			if (StringUtils.isBlank(aDate) && StringUtils.isBlank(bDate)) {
				Date date1 = format.parse(aDate);
				Date date2 = format.parse(bDate);
				str = date1.after(date2);
			}
		} catch (ParseException e) {
			// Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}

	public static Map<Integer, Long> timestamp() {
		Map<Integer, Long> timeMap = Maps.newHashMap();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		int[] yearArr = new int[] { 1, 1, 1, 2, 5, 1 };
		int[] arr = new int[] { 1, 2, 3, 5, 10, 11 };
		for (int i = 0; i < yearArr.length; i++) {
			calendar.add(Calendar.YEAR, -yearArr[i]);
			timeMap.put(arr[i], calendar.getTimeInMillis());
		}
		return timeMap;
	}

	public static Date getDateToOne() {
		Date date = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, 1);
		/**
		 * 1. getActualMinimum(Calendar.DAY_OF_MONTH)是拿到当月最小天数作为第一天
		 * 
		 * 2. calendar.set(Calendar.DAY_OF_MONTH, 1)也能获取当月第一天
		 */
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		System.out.println(calendar.getTime());
		String s = DateUtils.formatDate(calendar.getTime(), DateUtils.DATE_YYYY_MM_DD);
		System.out.println(s);
		return calendar.getTime();
	}

}
