package com.palmnest.application.core.util;


import com.palmnest.application.dto.DateTypeDto;
import net.sf.json.JSONObject;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.*;

/**
 * 日期转换帮助
 *
 * @author yb
 * @date 2014-04-12
 */
public class DateUtils {

	public DateUtils() {

	}

	public final static Calendar myc = Calendar.getInstance();

	public final static String YYYY_MM_DD_MM_HH_SS = "yyyy-MM-dd HH:mm:ss";

	public final static String YYYY_MM_DD = "yyyy-MM-dd";

	public final static String KEY = "d44f8e63ec99bdd64e09f164ced4f9aa";

	/**
	 * 获得当天时间
	 *
	 * @param parrten 输出的时间格式
	 * @return 返回时间
	 */
	public static String getTime(String parrten) {

		String timestr;
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyyMMddHHmmss";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		java.util.Date cday = new Date();
		timestr = sdf.format(cday);
		return timestr;
	}

	/**
	 * 获得当天日期
	 *
	 * @param parrten
	 * @return
	 */
	public static String getDate(String parrten) {

		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		return DateUtils.getTime(parrten);
	}

	/**
	 *  java 获取 获取某年某月 所有日期（yyyy-mm-dd格式字符串）
	 * @param year
	 * @param month
	 * @return
	 */
	public static List<String> getMonthFullDay(int year , int month){
	    SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");
	    List<String> fullDayList = new ArrayList<>(32);
	    // 获得当前日期对象
	    Calendar cal = Calendar.getInstance();
	    cal.clear();// 清除信息
	    cal.set(Calendar.YEAR, year);
	    // 1月从0开始
	    cal.set(Calendar.MONTH, month-1 );
	    // 当月1号
	    cal.set(Calendar.DAY_OF_MONTH,1);
	    int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	    for (int j = 1; j <= count ; j++) {
	        fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
	        cal.add(Calendar.DAY_OF_MONTH,1);
	    }
	    return fullDayList;
	}

	/**
     * 获取一天中间隔五分钟的所有时间点
     *
     * @return
     */
    public static List<String> getTimeLagMinute(int min) {
        ArrayList<String> list = new ArrayList<String>();//创建集合存储所有时间点
        for (int h = 0, m = 0; h < 24; m += min) {//创建循环，指定间隔五分钟
            if (m >= 60) {//判断分钟累计到60时清零，小时+1
                h++;
                m = 0;
            }
            if (h >= 24) {//判断小时累计到24时跳出循环，不添加到集合
                break;
            }

            /*转换为字符串*/
            String hour = String.valueOf(h);
            String minute = String.valueOf(m);

            /*判断如果为个位数则在前面拼接‘0’*/
            if (hour.length() < 2) {
                hour = "0" + hour;
            }
            if (minute.length() < 2) {
                minute = "0" + minute;
            }
            String beginTime=hour + ":" + minute;
            list.add(beginTime);//拼接为HH:mm格式，添加到集合
        }

        return list;
    }

    public static List<String> getTimeMin(int min){
    	ArrayList<String> list = new ArrayList<String>();//创建集合存储所有时间点
    	List<String> tList=getTimeLagMinute(min);
    	for(String beginTime:tList){
    		Date date=DateHelper.parseToDate(beginTime,DateHelper.TIME_HOUR_MINUTE);
    		Date day=addMinute(date, min, DateHelper.TIME_HOUR_MINUTE);
    		String endTime=DateHelper.formatDate(day, DateHelper.TIME_HOUR_MINUTE);

    		if("23:30".equals(beginTime)){
    			endTime="24:00";
    		}
    		String sysTime=beginTime+"-"+endTime;
    		System.out.println(sysTime);
    		list.add(sysTime);
    	}
    	return list;
    }

    public static BigDecimal calculateUsageDuration(Date startTime, Date endTime) {
        long durationInMillis = endTime.getTime() - startTime.getTime();
        double durationInHours = durationInMillis / (60.0 * 60 * 1000);
        // Round up to the nearest half hour
        return BigDecimal.valueOf(Math.ceil(durationInHours * 2) / 2);
    }

	/**
	 * 时间格式转换
	 *
	 * @param cday
	 * @param parrten
	 * @return
	 */
	public static String getTime(Date cday, String parrten) {

		String timestr;
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyyMMddHHmmss";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		timestr = sdf.format(cday);
		return timestr;
	}

	/**
	 * 日期格式转换
	 *
	 * @param parrten
	 * @return
	 */
	public static String getDate(Date date, String parrten) {

		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		return DateUtils.getTime(date, parrten);
	}

	/**
	 * 得到昨天的时间
	 *
	 * @return
	 */
	public static String getYestday() {

		String timestr;
		java.util.Calendar cc = myc;
		cc.roll(Calendar.DAY_OF_YEAR, -1);
		java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if ((cc.get(Calendar.MONTH) + 1) == 1 && cc.get(Calendar.DAY_OF_MONTH) == 1) {
			cc.roll(Calendar.YEAR, 1);
		}

		timestr = sdf.format(cc.getTime());
		return timestr;
	}

	/**
	 * 将字串转换为指定格式的日期
	 *
	 * @param time    时间
	 * @param parrten 为空时，将使用yyyy-MM-dd格式
	 * @return
	 */
	public static Date StrToDate(String time, String parrten) {

		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		ParsePosition pos = new ParsePosition(0);
		Date dt1 = formatter.parse(time, pos);
		return dt1;
	}


	/**
	 * @param t1      时间字符串
	 * @param parrten 原始格式
	 * @return
	 */
	public static String getTime(String t1, String parrten) {
		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy年MM月dd日");
		ParsePosition pos = new ParsePosition(0);
		Date dt1 = formatter.parse(t1, pos);
		return formatter2.format(dt1);
	}

	/**
	 * @param t1      时间字符串
	 * @param parrten 原始格式
	 * @return
	 */
	public static String getTimeDate(String t1, String parrten) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		String time = "";
		try {
			Date now = sdf.parse(t1);
			time = formatter.format(now);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("时间转换失败");
		}
		return time;
	}

	/**
	 * 将时间转换为parrten2格式
	 *
	 * @param t1       时间字符�?
	 * @param parrten  原时间格�?
	 * @param parrten2 要转化的格式
	 * @return
	 */
	public static String getTime(String t1, String parrten, String parrten2) {

		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		SimpleDateFormat formatter2 = new SimpleDateFormat(parrten2);
		ParsePosition pos = new ParsePosition(0);
		Date dt1 = formatter.parse(t1, pos);
		return formatter2.format(dt1);
	}


	/**
	 * 比较两个日期相差的天�?
	 *
	 * @param time1
	 * @param time2
	 * @return
	 */
	public static int compareTime2(String time1, String time2) {

		return compareStringTimes(time1, time2, "yyyy-MM-dd");
	}

	public static String addTime(String datetime, String parrten, long days) {

		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		ParsePosition pos = new ParsePosition(0);
		Date dt1 = formatter.parse(datetime, pos);
		long l = dt1.getTime() / 1000 + days * 24 * 60 * 60;
		dt1.setTime(l * 1000);
		String mydate = formatter.format(dt1);

		return mydate;
	}

	public static String jianTime(String datetime, String parrten, long days) {

		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		ParsePosition pos = new ParsePosition(0);
		Date dt1 = formatter.parse(datetime, pos);
		long l = dt1.getTime() / 1000 - days * 24 * 60 * 60;
		dt1.setTime(l * 1000);
		String mydate = formatter.format(dt1);

		return mydate;
	}

	/**
	 * 取得昨天的日�?,以今天为基准
	 *
	 * @return
	 */
	public static String getYestdayBaseToday() {

		String timestr;

		Calendar calendar = Calendar.getInstance();

		calendar.roll(Calendar.DAY_OF_YEAR, -1);

		Calendar tempCalendar = Calendar.getInstance();
		tempCalendar.setTime(calendar.getTime());
		if (tempCalendar.get(Calendar.DAY_OF_YEAR) == 1) {
			calendar.roll(Calendar.YEAR, -1);
		}

		java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		timestr = sdf.format(calendar.getTime());
		return timestr;

	}

	/**
	 * 取得指定日期的前�?�?
	 *
	 * @param date
	 * @return
	 */
	public static Date getPreDate(Date date) {

		Calendar calendar = Calendar.getInstance();

		Date tempDate = date;

		calendar.setTime(date);
		calendar.roll(Calendar.DAY_OF_YEAR, -1);

		Calendar cal = Calendar.getInstance();

		cal.setTime(tempDate);

		if (cal.get(Calendar.DAY_OF_YEAR) == 1) {
			calendar.roll(Calendar.YEAR, -1);
		}

		Date preDate = calendar.getTime(); // 得到前一天的日期
		return preDate;

	}

	/**
	 * @param date
	 * @return
	 * @author admin
	 * @version 2007-5-17
	 */
	public static String endDate(Date date) {

		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DAY_OF_MONTH, 1);
		String e = ca.get(ca.YEAR) + "-" + (ca.get(ca.MONTH) + 1) + "-" + ca.get(ca.DATE);
		return e;
	}

	/**
	 * @param date
	 * @return
	 * @author admin
	 * @version 2007-5-17
	 */
	public static String endDateYMD(Date date, int day) {

		Calendar nowTime = Calendar.getInstance();
		nowTime.setTime(date);
		nowTime.add(Calendar.MONTH, day);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String timestr = sdf.format(nowTime.getTime());
		return timestr;
	}

	/**
	 * 格式化日�?  指定格式
	 *
	 * @param date
	 * @param formatStyle
	 * @return
	 */
	public static String formatDate(Date date, String formatStyle) {
		String defaultStyle = "yyyy-MM-dd HH:mm:ss";
		if (formatStyle != null && !formatStyle.equals(""))
			defaultStyle = formatStyle;
		DateFormat df = new SimpleDateFormat(defaultStyle);
		String dt = df.format(date);
		return dt;
	}

	/**
	 * 格式化日�? 默认格式:yyyy-MM-dd HH:mm:ss
	 *
	 * @param date
	 * @return
	 */
	public static String formatDate(Date date) {
		return formatDate(date, null);
	}

	/**
	 * 描述：比较两个时间相差的天数
	 * 时间�?2010-1-14
	 * 作�?�：admin
	 * 参数�?
	 * 返回�?:0表示相等�?>0表示t1�?,<0表示t2�?
	 * 抛出异常�?
	 */
	public static int compareStringTimes(String t1, String t2, String parrten) {

		SimpleDateFormat formatter = new SimpleDateFormat(parrten);
		ParsePosition pos = new ParsePosition(0);
		ParsePosition pos1 = new ParsePosition(0);
		Date dt1 = formatter.parse(t1, pos);
		Date dt2 = formatter.parse(t2, pos1);

		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dt1);
		int day1 = calendar.get(Calendar.DAY_OF_YEAR);
		calendar.setTime(dt2);
		int day2 = calendar.get(Calendar.DAY_OF_YEAR);
		return (day1 - day2);

	}

	/**
	 * 获取某年上一个月
	 *
	 * @param currDate 当前时间
	 * @param parrten
	 * @return String
	 * @author
	 * @date 2010-2-10
	 * @remark
	 */
	public static String getPrevMonth(String currDate, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Calendar calendar = Calendar.getInstance();
		Date mydate = new Date();
		try {
			mydate = sdf.parse(currDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(mydate);
		calendar.add(Calendar.MONTH, -1);
		String result = sdf.format(calendar.getTime()).toString();
		return result;
	}

	/**
	 * 获取某年下一个月
	 *
	 * @param currDate
	 * @param parrten
	 * @return String
	 * @author
	 * @date 2010-2-10
	 * @remark
	 */
	public static String getNextMonth(String currDate, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Calendar calendar = Calendar.getInstance();
		Date mydate = new Date();
		try {
			mydate = sdf.parse(currDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(mydate);
		calendar.add(Calendar.MONTH, 1);
		String result = sdf.format(calendar.getTime()).toString();
		return result;
	}

	/**
	 * 获取上一�?
	 *
	 * @param currYear
	 * @return String
	 * @author
	 * @date 2010-2-10
	 * @remark
	 */
	public static String getPrevYear(String currYear) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Calendar calendar = Calendar.getInstance();
		Date mydate = new Date();
		try {
			mydate = sdf.parse(currYear);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(mydate);
		calendar.add(Calendar.YEAR, -1);
		String result = sdf.format(calendar.getTime()).toString();
		return result;
	}

	/**
	 * 获取下一�?
	 *
	 * @param currYear
	 * @return String
	 * @author
	 * @date 2010-2-10
	 * @remark
	 */
	public static String getNextYear(String currYear) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Calendar calendar = Calendar.getInstance();
		Date mydate = new Date();
		try {
			mydate = sdf.parse(currYear);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(mydate);
		calendar.add(Calendar.YEAR, 1);
		String result = sdf.format(calendar.getTime()).toString();
		return result;
	}


	/**
	 * 功能说明:得到指定月份的最后一天
	 *
	 * @return
	 * @author admin
	 * @version Feb 16, 2009
	 */
	public static String getLastDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		//当前月＋1
		cal.add(Calendar.MONTH, 1);
		//将下个月1号作为日期初始值
		cal.set(Calendar.DATE, 1);
		//下个月的1号减去一天，即得到当前月最后一天
		cal.add(Calendar.DATE, -1);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		return day_end;
	}

	/**
	 * 得到指定月份的第一天
	 *
	 * @param date
	 * @return
	 */
	public static String getFirstDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		//本月月1号作为日期初始值
		cal.set(Calendar.DATE, 1);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		return day_end;
	}

	public static String getPreWeekDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, -7);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		return day_end;
	}

	public static String getPreMonthDate(Date date, int monthcount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, monthcount);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		return day_end;
	}

	public static String getPreMonthDates(Date date, int monthcount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, monthcount);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
		String day_end = df.format(cal.getTime());
		return day_end;
	}

	public static String getCurWeekDate() {
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		return df.format(cal.getTime());
	}

	/**
	 * 功能说明:得到指定月份的最后一�?
	 *
	 * @return
	 * @author admin
	 * @version Feb 16, 2009
	 */
	public static String getLastDate(String date) {
		Date newDate = DateUtils.StrToDate(date, "");
		//Date date=new Date(month);
		Calendar cal = Calendar.getInstance();
		cal.setTime(newDate);
		//当前月＋1，即下个�?
		cal.add(Calendar.MONTH, 1);
		//将下个月1号作为日期初始zhii
		cal.set(Calendar.DATE, 1);
		//下个�?1号减去一天，即得到当前月�?后一�?
		cal.add(Calendar.DATE, -1);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		//System.out.println("day_end>>>"+day_end);
		return day_end;
	}

	/**
	 * 功能说明:得到�?年的�?后一�?
	 *
	 * @return
	 * @author admin
	 * @version Feb 16, 2009
	 */
	public static String getLastYearByDate(String year) {
		Calendar cal = Calendar.getInstance();
		String newYear = year + "-01-01";//�?年的第一�?
		Date date = DateUtils.StrToDate(newYear, "yyyy-mm-dd");
		cal.setTime(date);
		cal.add(Calendar.MONTH, 12);
		cal.add(Calendar.DATE, -1);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String day_end = df.format(cal.getTime());
		//System.out.println("day_end>>>"+day_end);
		return day_end;
	}

	/**
	 * 功能说明:得到两个时间相差的小时数
	 *
	 * @param: @param t1 以前的时间
	 * @param: @param t2 最新的时间
	 * @param: @param parrten  格式
	 * @return: void
	 * @author: admin
	 * @date: 2012 3 7 10:28:49
	 */
	public static Double compareStringTimesToHour(Date t1, Date t2, String parrten) {
		Double result = null;
		SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		//默认为毫秒，除以1000是为了转换成秒
		long interval = (t2.getTime() - t1.getTime()) / 1000;//秒
		long day = interval / (24 * 3600);//天
		long hour = interval % (24 * 3600) / 3600;//小时
		long minute = interval % 3600 / 60;//分钟

		Double dayToHour = new Double(Double.parseDouble(new Long(day).toString()) * 24);
		Double hourToHour = new Double(Double.parseDouble(new Long(hour).toString()));
		Double minuteToHour = new Double(NumberUtils.divide(Double.parseDouble(new Long(minute).toString()), 60d, 1));
		result = new Double(dayToHour.doubleValue() + hourToHour.doubleValue() + minuteToHour.doubleValue());
		return result;
	}


	/**
	 * 功能说明:得到两个时间相差的小时数
	 *
	 * @param: @param t1 以前的时间
	 * @param: @param t2 最新的时间
	 * @author: qzy
	 * @date: 2012 3 7 10:28:49
	 */
	public static BigDecimal compareStringTimesToHour(Date tbefore, Date tAfter) {
		Double result = null;

		//默认为毫秒，除以1000是为了转换成秒
		long interval = (tAfter.getTime() - tbefore.getTime()) / 1000;//秒
		long day = interval / (24 * 3600);//天
		long hour = interval % (24 * 3600) / 3600;//小时
		long minute = interval % 3600 / 60;//分钟

		Double dayToHour = new Double(Double.parseDouble(new Long(day).toString()) * 24);
		Double hourToHour = new Double(Double.parseDouble(new Long(hour).toString()));
		Double minuteToHour = new Double(NumberUtils.divide(Double.parseDouble(new Long(minute).toString()), 60d, 1));
		result = new Double(dayToHour.doubleValue() + hourToHour.doubleValue() + minuteToHour.doubleValue());

		MathContext mc = new MathContext(2, RoundingMode.HALF_DOWN);
		BigDecimal resultBd = new BigDecimal(result, mc);
		return resultBd;
	}

	public static String getNextDayDate(Date curDate, Integer dayCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);

		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.add(Calendar.DAY_OF_MONTH, dayCount.intValue());
		return sdf.format(calendar.getTime());
	}

	public static Date addDay(Date curDate, Integer dayCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Date returnDate = null;
		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
			calendar.add(Calendar.DAY_OF_MONTH, dayCount.intValue());
			returnDate = sdf.parse(sdf.format(calendar.getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return returnDate;
	}


	public static Date addHour(Date curDate, Integer dayCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Date returnDate = null;
		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
			calendar.add(Calendar.HOUR_OF_DAY, dayCount.intValue());
			returnDate = sdf.parse(sdf.format(calendar.getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return returnDate;
	}

	public static Date addMinute(Date curDate, Integer dayCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Date returnDate = null;
		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
			calendar.add(Calendar.MINUTE, dayCount.intValue());
			returnDate = sdf.parse(sdf.format(calendar.getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return returnDate;
	}


	/**
	 * 功能说明:以传入的时间为基础计算hourCount为目标时间，最终以parrten格式返回
	 *
	 * @param: @param curDate
	 * @param: @param hourCount
	 * @param: @param parrten
	 * @param: @return
	 * @return: String
	 * @author:admin
	 * @date: 2012 5 16 13:17:33
	 */
	public static String getNextHourDate(Date curDate, Integer hourCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);

		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.add(Calendar.HOUR_OF_DAY, hourCount.intValue());
		return sdf.format(calendar.getTime());
	}

	/**
	 * 功能说明:以传入的时间为基础计算hourCount为目标时间，最终以parrten格式返回
	 *
	 * @param: @param curDate
	 * @param: @param hourCount
	 * @param: @param parrten
	 * @param: @return
	 * @return: String
	 * @author:admin
	 * @date: 2012 5 16 13:17:33
	 */
	public static String getPreHourDate(Date curDate, Integer hourCount, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM-dd";
		}
		java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);

		Calendar calendar = Calendar.getInstance();
		try {
			String strDate = DateUtils.getDate(curDate, parrten);
			calendar.setTime(sdf.parse(strDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.add(Calendar.HOUR_OF_DAY, -hourCount.intValue());
		return sdf.format(calendar.getTime());
	}

	/**
	 * 功能说明:得到指定日期的month个月
	 *
	 * @param: @param currDate
	 * @param: @param month
	 * @param: @param parrten
	 * @param: @return
	 * @return: String
	 * @author:admin
	 * @date: 2012 7 6 09:39:44
	 */
	public static String getNextMonthDate(String currDate, Integer month, String parrten) {
		if (parrten == null || parrten.equals("")) {
			parrten = "yyyy-MM";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Calendar calendar = Calendar.getInstance();
		Date mydate = new Date();
		try {
			mydate = sdf.parse(currDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(mydate);
		calendar.add(Calendar.MONTH, month.intValue());
		String result = sdf.format(calendar.getTime()).toString();
		return result;
	}

	/**
	 * 功能说明：将毫秒数转换为时间
	 *
	 * @param longTime 毫秒
	 * @param parrten  样式
	 * @return
	 */
	public static String paseLongToDate(long longTime, String parrten) {
		SimpleDateFormat sdf = new SimpleDateFormat(parrten);
		Date date = new Date(longTime);
		String result = sdf.format(date);
		return result;
	}

	public static String paseDateToLong(String date) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date paseDate = sf.parse(date);
			return paseDate.getTime() + "";
		} catch (ParseException e) {
			System.out.println("日期解析错误，DateUtils[paseDateToLong()]");
			return System.currentTimeMillis() + "";
		}
	}


	/**
	 * 　　*功能：截取两个日期之间的天数
	 * 　　* @param String beginDate,String endDate
	 * 　　* @return int
	 * 　　* @throws ParseException
	 * 　　*
	 */
	public static int getDay(String beginDate, String endDate, String parrten) {
		SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
		Date d1 = null;
		Date d2 = null;
		try {
			d1 = sim.parse(beginDate);
			d2 = sim.parse(endDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return (int) ((d2.getTime() - d1.getTime()) / (3600L * 1000 * 24));
	}

	/**
	 * 功能说明：返回edTime 前interval个月的时间
	 *
	 * @param edTime   结束时间
	 * @param interval
	 * @return
	 */
	public static String getDate(int interval) {
		StringBuffer sbf = new StringBuffer();
		String curdate = getDate("yyyyMM");
		String year = curdate.substring(0, 3);
		String month = curdate.substring(3);
		int i = Integer.parseInt(month);
		if (interval > i) {
			int retYear = Integer.parseInt(year) - 1;
			int retMonth = i + 12 - interval;
			sbf.append(retYear + "" + retMonth + "01");
		} else {
			int retMonth = i - interval;
			sbf.append(year + "" + retMonth + "01");
		}
		return sbf.toString();
	}

	//取一周前的时间，返回年月日格式时间
	public static Date getPreWeekDate2(Date date) {
		try {
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.add(Calendar.DATE, -7);
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

			String day_end = df.format(cal.getTime());
			return df.parse(day_end);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}


	/**
	 * 功能说明:得到两个时间相差的分钟数
	 *
	 * @param: @param t1 以前的时间
	 * @param: @param t2 最新的时间
	 * @param: @param parrten  格式
	 * @return: void
	 * @author: admin
	 * @date: 2012 3 7 10:28:49
	 */
	public static int compareStringTimesToMinute(Date t1, Date t2) {
		Long result;
		//默认为毫秒，除以1000是为了转换成秒
		Long interval = (t2.getTime() - t1.getTime()) / 1000;//秒
		result = interval % 60 == 0 ? (interval / 60) : (interval / 60) + 1;
		return result.intValue();
	}


	/**
	 * 得到今天以前任何一天的时间的时间
	 */
	public static String getBeforeNowDays(int days) {
		String timestr;
		java.util.Calendar cc = Calendar.getInstance();
		cc.roll(Calendar.DAY_OF_YEAR, -days);
		java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if ((cc.get(Calendar.MONTH) + 1) == 1 && cc.get(Calendar.DAY_OF_MONTH) == 1) {
			cc.roll(Calendar.YEAR, 1);
		}
		timestr = sdf.format(cc.getTime());
		return timestr;
	}


	//将字符串时间转为date
	public static Date getDateByString(String time) {
		try {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return sf.parse(time);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	//将字符串时间转为date
	public static Date getDateByString(String time, String formatStr) {
		try {
			SimpleDateFormat sf = new SimpleDateFormat(formatStr);
			return sf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

//	public static void main(String[] args) {
//		System.out.println(getPreMonthDates(new Date(),-6));
//		/*String varYM="201211";
//		String last=getLastDate(varYM.substring(0, 4)+"-"+varYM.substring(4)+"-01");
//		System.out.println(last);//2012-11-30
//		System.out.println(last.substring(8));
//		System.out.println(getDate("yyyy-MM-dd"));
//		System.out.println(getPreWeekDate2(new Date()));
//		System.out.println(getBeforeNowDays(0));*/
//
//		/*System.out.println(getDateByString("2015-10-28 10:20:16"));
//		System.out.println(getDateByString("2015-10-28 10:18:41"));
//		System.out.println(compareStringTimesToMinute(getDateByString("2015-10-28 10:18:41"),getDateByString("2015-10-28 10:20:16")));
//		*/
//		//System.out.println(DateUtils.formatDate(DateUtils.StrToDate("2017-05","yyyy-MM"),"yyyy-MM"));
//		//System.out.println(calculateTime("2015-10-28 10:10:06", "2015-10-28 10:20:16.0"));
//
//		//System.out.println(compareStringTimesToHour(getDateByString("2015-10-28 08:30:00"),getDateByString("2015-10-28 10:30:00"),"yyyy-MM-dd HH:mm"));
//
////		String str11="2018-10-22 16:30:00";
////		Date useStartTime=DateUtils.getDateByString(str11, DateUtils.YYYY_MM_DD_MM_HH_SS);
////		String str22="2018-10-22 20:30:00";
////		Date useEndTime=DateUtils.getDateByString(str22, DateUtils.YYYY_MM_DD_MM_HH_SS);
////
////
////		int min=1800;
////		int max=2300;
////
////		String currentDateStr=DateUtils.formatDate(useStartTime, "yyyy-MM-dd HH:mm");
////		useStartTime=DateUtils.getDateByString(currentDateStr, "yyyy-MM-dd HH:mm");
//
//		//getIncludeTime(useStartTime, useEndTime, min, max);
//
//
//	}

	public static Map<String, Date> getIncludeTime(Date useStartTime, Date useEndTime, Date ruleStartTime,
									 Date ruleEndTime) {
		boolean isOverTime = true;
		boolean isOver = false;//是否过线
		Map<String, Date> recodeMap = new HashMap<>();
		int addMinuteNo = 0;


		String ymdStr = DateUtils.getDate(useStartTime, "yyyy-MM-dd");

		String ruleStartTimeStr = DateUtils.formatDate(ruleStartTime, "HH:mm:ss");
		Date newRuleStartTime = DateUtils.getDateByString(ymdStr + " " + ruleStartTimeStr, DateUtils.YYYY_MM_DD_MM_HH_SS);
		if (ruleStartTimeStr.equals("00:00:00")) {
			newRuleStartTime = DateUtils.addDay(newRuleStartTime, -1, DateUtils.YYYY_MM_DD_MM_HH_SS);
		}

		String ruleEndTimeStr = DateUtils.formatDate(ruleEndTime, "HH:mm:ss");
		Date nowRuleEndTime = DateUtils.getDateByString(ymdStr + " " + ruleEndTimeStr, DateUtils.YYYY_MM_DD_MM_HH_SS);
		if (ruleEndTimeStr.equals("00:00:00")) {
			nowRuleEndTime = DateUtils.addDay(nowRuleEndTime, 1, DateUtils.YYYY_MM_DD_MM_HH_SS);
		}

		while (isOverTime) {


			Date strTempTime = DateUtils.addMinute(useStartTime, addMinuteNo, DateUtils.YYYY_MM_DD_MM_HH_SS);
			if (strTempTime.compareTo(useEndTime) <= 0) {
				System.out.println("strTempStr now ====:" + strTempTime.toLocaleString());
				//if(strTempTime>=newRuleStartTime && strTempTime<=nowRuleEndTime){
				if (strTempTime.compareTo(newRuleStartTime) >= 0 && strTempTime.compareTo(nowRuleEndTime) <= 0) {
					if (!isOver) {
						recodeMap.put("minDate", strTempTime);
						isOver = true;
					} else {
						recodeMap.put("maxDate", strTempTime);
					}
					System.out.println("strTempStr====:" + strTempTime.toLocaleString());

				}
				if (strTempTime.compareTo(useEndTime) == 0) {
					isOverTime = false;
				}
			}
			useStartTime = strTempTime;
			addMinuteNo = 30;

		}
		return recodeMap;
	}

	//根据传入的毫秒数算出与现在相差的时间(格式“天时分”)
	public static String getTimeDistanceToNow(Long time) {
		String str = "";
		if (time != null && time > 0) {
			long now = new Date().getTime();
			long timeSpan = now - time;
			if (timeSpan / (1000 * 60 * 60 * 24) > 1) {
				str += (timeSpan / (1000 * 60 * 60 * 24)) + "天";
			}
			if (timeSpan % (1000 * 60 * 60 * 24) > 0) {
				str += ((timeSpan % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) + "小时";
			}
			if (timeSpan % (1000 * 60 * 60) > 0) {
				str += ((timeSpan % (1000 * 60 * 60)) / (1000 * 60)) + "分钟";
			}
		}
		return str;
	}

	/**
	 * 功能说明:得到两个时间相差的小时数
	 *
	 * @param: @param t1 以前的时间
	 * @param: @param t2 最新的时间
	 * @param: @param parrten  格式
	 * @return: void
	 * @author: admin
	 * @date: 2012 3 7 10:28:49
	 */
	public static String compareStringTimesToHour1(Long time, Long time1) {
		String str = "";
		if (time != null && time > 0) {
			long now = new Date().getTime();
			if (time1 != null && time1 > 0) {
				now = time1;
			}

			long timeSpan = now - time;
			if (timeSpan / (1000 * 60 * 60 * 24) > 1) {
				str += (timeSpan / (1000 * 60 * 60 * 24)) + "天";
			}
			if (timeSpan % (1000 * 60 * 60 * 24) > 0) {
				str += ((timeSpan % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) + "小时";
			}
			if (timeSpan % (1000 * 60 * 60) > 0) {
				str += ((timeSpan % (1000 * 60 * 60)) / (1000 * 60)) + "分钟";
			}
		}
		return str;
	}

	/**
	 * 功能说明:传入分钟数计算将分钟转化为天/时/分
	 */
	public static String parseToDay(Long time) {
		String str = "";
		if (time != null && time > 0) {
			if ((time / (60 * 24)) > 1) {
				str += (time / (60 * 24)) + "天";
			}
			if (((time % (60 * 24)) / 60) > 0) {
				str += ((time % (60 * 24)) / 60) + "小时";
			}
			if ((time % 60) > 0) {
				str += (time % (60)) + "分钟";
			}
		}
		return str;
	}

	/**
	 * 比较时间大小,返回 0 时间相等 小于0 开始时间小于结束时间 大于0 开始时间大于结束时间
	 */
	public static int timeDifference(String beginTime, String endTime) {
		java.text.DateFormat df = new java.text.SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		java.util.Calendar c1 = java.util.Calendar.getInstance();
		java.util.Calendar c2 = java.util.Calendar.getInstance();
		try {
			c1.setTime(df.parse(beginTime));
			c2.setTime(df.parse(endTime));
		} catch (java.text.ParseException e) {
			System.err.println("格式不正确");
		}
		return c1.compareTo(c2);
	}

	/**
	 * 比较日期大小,返回 0 时间相等 小于0 开始时间小于结束时间 大于0 开始时间大于结束时间
	 */
	public static int timeDayDifference(String beginTime, String endTime) {
		java.text.DateFormat df = new java.text.SimpleDateFormat(
				"yyyy-MM-dd");
		java.util.Calendar c1 = java.util.Calendar.getInstance();
		java.util.Calendar c2 = java.util.Calendar.getInstance();
		try {
			c1.setTime(df.parse(beginTime));
			c2.setTime(df.parse(endTime));
		} catch (java.text.ParseException e) {
			System.err.println("格式不正确");
		}
		return c1.compareTo(c2);
	}

	/**
	 * 计算开始时间到结束时间相差几个15分钟
	 *
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws ParseException
	 */
	public static long calculateTime(String startTime, String endTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date startDate = sdf.parse(startTime);
			Date endDate = sdf.parse(endTime);
			Calendar dateOne = Calendar.getInstance(),
					dateTwo = Calendar.getInstance();
			dateOne.setTime(startDate);    //设置为当前系统时间
			dateTwo.setTime(endDate);         //设置为2015年1月15日
			long timeOne = dateOne.getTimeInMillis();
			long timeTwo = dateTwo.getTimeInMillis();
			long minute = (timeTwo - timeOne) / (1000 * 60);//转化minute
			System.out.println("相隔" + minute + "分钟");
			return minute;
		} catch (Exception e) {
			return -1;
		}

	}

	/**
	 * 时间转换为时间戳
	 *
	 * @param format
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public static long getTimeCur(String format, Date date) throws ParseException {
		SimpleDateFormat sf = new SimpleDateFormat(format);
		return sf.parse(sf.format(date)).getTime();
	}

	public static String getWeekOfDate(Date dt) {
		String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	public static String getWeekOfDates(Date dt) {
		String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	public static List<WeekDate> getWeek() {
//    	LocalDate today = LocalDate.now();
		String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
		List<WeekDate> weekList = new ArrayList<WeekDate>();
		LocalDate today = LocalDate.now();
		for (int i = 0; i < weekDays.length; i++) {
			WeekDate week = new WeekDate();
			String dateTime = "";
			int weekNo = i;
			int isToday = 0;
			if (i == 0) {
				dateTime = today.with(DayOfWeek.SUNDAY).toString();
				weekNo = 7;
			} else if (i == 1) {
				dateTime = today.with(DayOfWeek.MONDAY).toString();
			} else if (i == 2) {
				dateTime = today.with(DayOfWeek.TUESDAY).toString();
			} else if (i == 3) {
				dateTime = today.with(DayOfWeek.WEDNESDAY).toString();
			} else if (i == 4) {
				dateTime = today.with(DayOfWeek.THURSDAY).toString();
			} else if (i == 5) {
				dateTime = today.with(DayOfWeek.FRIDAY).toString();
			} else if (i == 6) {
				dateTime = today.with(DayOfWeek.SATURDAY).toString();
			}
			if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
				isToday = 1;
			}
			week.setDateTime(dateTime);
			week.setIsToday(isToday);
			week.setWeekName(weekDays[i]);
			week.setWeekNo(weekNo);
			weekList.add(week);
		}
		return weekList;
	}

	/**
	 * 获取当前日期的整周
	 *
	 * @return
	 * @throws IOException
	 * @throws NoSuchProviderException
	 * @throws NoSuchAlgorithmException
	 * @throws KeyManagementException
	 */
	public static List<WeekDate> getWeekOfSysDate() {
		List<WeekDate> weekList = new ArrayList<WeekDate>();
		LocalDate today = LocalDate.now();
		try {
			for (int i = 1; i <= 7; i++) {
				WeekDate week = new WeekDate();
				String weekName = "";
				String dateTime = "";
				int isWorking = 0;
				int isToday = 0;
				if (i == 1) {
					weekName = "星期一";
					dateTime = today.with(DayOfWeek.MONDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 2) {
					weekName = "星期二";
					dateTime = today.with(DayOfWeek.TUESDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 3) {
					weekName = "星期三";
					dateTime = today.with(DayOfWeek.WEDNESDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 4) {
					weekName = "星期四";
					dateTime = today.with(DayOfWeek.THURSDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 5) {
					weekName = "星期五";
					dateTime = today.with(DayOfWeek.FRIDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 6) {
					weekName = "星期六";
					dateTime = today.with(DayOfWeek.SATURDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				} else if (i == 7) {
					weekName = "星期日";
					dateTime = today.with(DayOfWeek.SUNDAY).toString();
					Integer dataType = getDateType(dateTime);
					if (dataType == 0) {//是工作日
						isWorking = 1;
					}
					if (dateTime.compareTo(today.toString()) == 0) {//判断是否为今天
						isToday = 1;
					}
				}
				week.setWeekName(weekName);
				week.setIsToday(isToday);
				week.setDateTime(dateTime);
				week.setIsWorking(isWorking);
				week.setWeekNo(i);
				weekList.add(week);
			}
		} catch (Exception e) {
			System.out.println("获取周期数据失败");
		}
		return weekList;
	}

	public static int getDateType(String time) {
		Integer dataType = -1;
		try {
			String date = DateUtils.getTimeDate(time, "yyyyMMdd");
			//正常工作日对应结果为 0, 法定节假日对应结果为 1, 节假日调休补班对应的结果为 2，休息日对应结果为 3
			String jsonStr = HttpKit.get("http://api.goseek.cn/Tools/holiday?date=" + date, false);
			Map<String, Object> jsApiMap = com.alibaba.fastjson.JSONObject.parseObject(jsonStr);
			if (null != jsApiMap && jsApiMap.containsKey("code")) {
//    			System.out.println(jsApiMap.get("code"));
				if (jsApiMap.get("code").equals(10000)) {
					dataType = (Integer) jsApiMap.get("data");
				}
			}
//    		System.out.println(time+":"+dataType);
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("获取日期类型失败");
		}
		return dataType;
	}


	/**
	 * 判断指定日期是否为周六
	 *
	 * @return
	 */
	public static boolean checkIsSaturday(Date theDate) {
		boolean isSaturday = false;
		Calendar cal = Calendar.getInstance();
		cal.setTime(theDate);

		if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
			isSaturday = true;
		}
		return isSaturday;
	}

	public static boolean checkIsOver(String time, int isOver) throws Exception {
		boolean isOverTime = false;//没有超过时间
		SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD);
		try {
			Date sysDate = sdf.parse(sdf.format(new Date()));
			Date weekDate = sdf.parse(time);
			if (sysDate.compareTo(weekDate) == 0) {//当前时间和订餐时间相等时
				if (isOver == 1) {//如果已经超过了数据字典中设置的时间，就返回true,代表已经超过时间了
					isOverTime = true;
				} else {//如果未超过了数据字典中设置的时间，就返回false,代表没有超过时间了
					isOverTime = false;
				}
			} else if (sysDate.after(weekDate)) {//当前时间大于订餐时间
				isOverTime = true;
			} else {
				isOverTime = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}
		return isOverTime;
	}

	public static List<DateTypeDto> getDateTypeInfo(int year, int month) throws Exception {
		List<DateTypeDto> dates = new ArrayList<DateTypeDto>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		cal.set(Calendar.DATE, 1);
		try {
			while (cal.get(Calendar.YEAR) == year &&
					cal.get(Calendar.MONTH) < month) {
				String date = sdf.format((Date) cal.getTime().clone());
				int type = getDateType(sdf.format((Date) cal.getTime().clone()));
				DateTypeDto dto = new DateTypeDto(date, type);
				dates.add(dto);
				cal.add(Calendar.DATE, 1);
			}
		} catch (Exception e) {
			throw new Exception(e);
		}
		return dates;
	}

	/**
	 * 获取该月天数
	 *
	 * @param year
	 * @param month
	 * @return
	 * @throws Exception
	 */
	public static List<Date> getDates(int year, int month) throws Exception {
		List<Date> dates = new ArrayList<Date>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		cal.set(Calendar.DATE, 1);
		while (cal.get(Calendar.YEAR) == year &&
				cal.get(Calendar.MONTH) < month) {
			int day = cal.get(Calendar.DAY_OF_WEEK);

			if (!(day == Calendar.SUNDAY || day == Calendar.SATURDAY)) {
				if (getDateType(sdf.format((Date) cal.getTime().clone())) == 0) {
					dates.add((Date) cal.getTime().clone());
				}
			}
			cal.add(Calendar.DATE, 1);
		}
		return dates;

	}

	/**
	 * 获取近期节假日
	 *
	 * @param date 年-月(2019-4)
	 * @return
	 * @throws Exception
	 */
	public static List<DateTypeDto> getHoliday(String date) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String url = "http://v.juhe.cn/calendar/month";
		String paramentStr = "year-month=" + date + "&key=" + KEY;
		List<DateTypeDto> mapList = new ArrayList<DateTypeDto>();
		try {
			String res = HttpKit.Post(paramentStr, url);
			JSONObject jsonObj = JSONObject.fromObject(res);
			//成功了且result有数据
			if (jsonObj != null && jsonObj.containsKey("reason") && "Success".equals(jsonObj.get("reason")) && jsonObj.containsKey("result") && jsonObj.get("result") != null
					&& StringUtil.isNotEmpty(jsonObj.get("result").toString())) {
				JSONObject resultJsonObj = (JSONObject) jsonObj.get("result");
				JSONObject dataJsonObj = (JSONObject) resultJsonObj.get("data");
				if (dataJsonObj.containsKey("holiday_array") && dataJsonObj.get("holiday_array") != null && StringUtil.isNotEmpty(dataJsonObj.get("holiday_array").toString())) {
					net.sf.json.JSONArray arrayJson = dataJsonObj.getJSONArray("holiday_array");
					if (arrayJson != null && arrayJson.size() > 0) {
						for (int i = 0; i < arrayJson.size(); i++) {
							JSONObject obj = arrayJson.getJSONObject(i);
							if (obj != null && obj.containsKey("list") && obj.get("list") != null) {
								net.sf.json.JSONArray array = (net.sf.json.JSONArray) obj.get("list");
								if (array != null && array.size() > 0) {
									for (int k = 0; k < array.size(); k++) {
										JSONObject dateObj = array.getJSONObject(k);
										if (dateObj.get("date") != null && StringUtil.isNotEmpty(dateObj.get("date").toString())) {
											int type = Integer.parseInt(dateObj.get("status") == null ? "-1" : dateObj.get("status").toString());
											String dateInfo = sdf.format(sdf.parse(dateObj.get("date").toString()));
											DateTypeDto dto = new DateTypeDto(dateInfo, type);
											mapList.add(dto);
										}
									}
								}
							}
						}
					}
				}
			}
		} catch (Exception e) {
			throw new Exception(e);
		}
		return mapList;
	}

	/**
	 * 获取两个日期之间的所有日期
	 *
	 * @param startTime 开始日期
	 * @param endTime   结束日期
	 * @return
	 */
	public static List<String> getDays(String startTime, String endTime) {

		// 返回的日期集合
		List<String> days = new ArrayList<String>();

		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date start = dateFormat.parse(startTime);
			Date end = dateFormat.parse(endTime);

			Calendar tempStart = Calendar.getInstance();
			tempStart.setTime(start);

			Calendar tempEnd = Calendar.getInstance();
			tempEnd.setTime(end);
			tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
			while (tempStart.before(tempEnd)) {
				days.add(dateFormat.format(tempStart.getTime()));
				tempStart.add(Calendar.DAY_OF_YEAR, 1);
			}

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

		return days;
	}

//    public static void main(String[] args) {
////    	String date="2019-4";
////		try {
////			List<DateTypeDto> mapList = getHoliday(date);
////			net.sf.json.JSONArray a=net.sf.json.JSONArray.fromObject(mapList);
////	    	System.out.println(a);
////		} catch (Exception e) {
////			// TODO Auto-generated catch block
////			e.printStackTrace();
////		}
//    	SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
//    	Calendar cal = Calendar.getInstance();
//        try {
//			cal.setTime(sdf.parse("2019-04-13"));
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//        System.out.println(cal.get(Calendar.DAY_OF_WEEK));
//        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
//        System.out.println(w);
//        if(w<=0){
//            w=7;
//        }
//        System.out.println(w);
//    }
}
