
export const DateUtil = {
    timeSchemeKey: {
        "today": "today",
        "yesterday": "yesterday",
        "week": "week",
        "month": "month",
        "premonth": "premonth",
        "quarter": "quarter",
        "year": "year",
        "days7": "days7",
        "days28": "days28",
        "days84": "days84",
        "halfyear": "halfyear",
        "oneyear": "oneyear"
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 日期格式化
       * @description 将条件转成字符结果
       * @url format(date, format)
       * @method $instance.format(date, format)
       * @param date 必选 Date|String 需要格式化日期
       * @param format 必选 String 格式化类型
       * @return Date
       * @number 60  
       */
    format: function (date, format = "yyyy-MM-dd hh:mm:ss") {
        if (!date) return;
        if (typeof date == "string")
            date = DateUtil.strToDate(date);
        format = format.replace(/HH/, "hh");
        var o = {
            "M+": date.getMonth() + 1, // month
            "d+": date.getDate(), // day
            "D+": date.getDate(), // day
            "h+": date.getHours(), // hour
            "H+": date.getHours(), // hour
            "m+": date.getMinutes(), // minute
            "s+": date.getSeconds(), // second
            "q+": Math.floor((date.getMonth() + 3) / 3), // quarter
            "S": date.getMilliseconds()
            // millisecond
        }
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4
                - RegExp.$1.length));
        if (/(Y+)/.test(format))
            format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4
                - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间：毫秒差间隔
       * @description dt1与dt2日期之间毫秒差间隔
       * @url milliSecondsBetween(dt1, dt2)
       * @method $instance.milliSecondsBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    milliSecondsBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        return Math.abs(dt1.getTime() - dt2.getTime());
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间：秒差间隔
       * @description dt1与dt2日期之间秒差间隔
       * @url secondsBetween(dt1, dt2)
       * @method $instance.secondsBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    secondsBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.abs((dt1.getTime() - dt2.getTime()) / 1000);
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间分差间隔
       * @description dt1与dt2日期之间分差间隔
       * @url minutesBetween(dt1, dt2)
       * @method $instance.minutesBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    // 分差
    minutesBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.floor(Math.abs((dt1.getTime() - dt2.getTime())
            / (1000 * 60)));
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间时差间隔
       * @description dt1与dt2日期之间时差间隔
       * @url hoursBetween(dt1, dt2)
       * @method $instance.hoursBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    // 小时差
    hoursBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.floor(Math.abs((dt1.getTime() - dt2.getTime())
            / (1000 * 3600)));
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间天差间隔
       * @description dt1与dt2日期之间天差间隔
       * @url daysBetween(dt1, dt2)
       * @method $instance.daysBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    daysBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.floor(Math.abs((dt1.getTime() - dt2.getTime())
            / (1000 * 3600 * 24)));
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间月差间隔
       * @description dt1与dt2日期之间月差间隔
       * @url daysBetween(dt1, dt2)
       * @method $instance.daysBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    monthsBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.abs((dt1.getFullYear() - dt2.getFullYear()) * 12)
            + Math.abs(dt1.getMonth() - dt2.getMonth());
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title dt1与dt2日期之间年差间隔
       * @description dt1与dt2日期之间年差间隔
       * @url yearsBetween(dt1, dt2)
       * @method $instance.yearsBetween(dt1, dt2)
       * @param dt1 必选 Date|String 日期时间1
       * @param dt2 必选 Date|String 日期时间2
       * @return Int
       * @number 60  
       */
    yearsBetween: function (dt1, dt2) {
        if (typeof dt1 == "string")
            dt1 = DateUtil.strToDate(dt1);
        if (typeof dt2 == "string")
            dt2 = DateUtil.strToDate(dt2);
        if (!dt1 || !dt2)
            return null;
        return Math.abs(dt1.getFullYear() - dt2.getFullYear());
    },

    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获取中文星期
       * @description 获取中文星期
       * @url getWeekCn(dt)
       * @method $instance.getWeekCn(dt)
       * @param dt 必选 Date|String 日期时间
       * @return String
       * @number 60  
       */
    getWeekCn: function (dt) {
        var dayNames = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
            "星期六");
        if (typeof dt == "string")
            dt = DateUtil.strToDate(dt);
        return dayNames[dt.getDay()];
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获取数字星期
       * @description 获取数字星期
       * @url getWeek(dt)
       * @method $instance.getWeek(dt)
       * @param dt 必选 Date|String 日期时间
       * @return String
       * @number 60  
       */
    getWeek: function (dt) {
        if (typeof dt == "string")
            dt = DateUtil.strToDate(dt);
        return dt.getDay();
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 是否时间日期
       * @description 是否时间日期
       * @url isDateTime(dateString)
       * @method $instance.isDateTime(dateString)
       * @param dateString 必选 Date|String 日期时间
       * @return boolean
       * @number 60  
       */
    isDateTime: function (dateString) {
        if (dateString.trim() == "")
            return false;
        // 年月日时分秒正则表达式
        var r = dateString
            .match(/^(\d{1,4})\-(\d{1,2})\-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
        var r1 = dateString
            .match(/^(\d{1,4})\-(\d{1,2})\-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2}).(\d{1,6})$/);
        var r2 = dateString
            .match(/^(\d{1,4})\-(\d{1,2})\-(\d{1,2}) (\d{1,2}):(\d{1,2})$/);
        if (r == null && r1 == null && r2 == null) {
            return false;
        }
        r = r || r1 || r2;
        if (r.length == 6) {// 时间格式为：2018-04-11 17:31
            var d1 = new Date(r[1], r[2] - 1, r[3], r[4], r[5]);
            let num = (d1.getFullYear() == r[1] && (d1.getMonth() + 1) == r[2]
                && d1.getDate() == r[3] && d1.getHours() == r[4] && d1
                    .getMinutes() == r[5]);
            if (num == 0) {
                return false;
            } else
                return true;
        }

        var d = new Date(r[1], r[2] - 1, r[3], r[4], r[5], r[6]);
        let num = (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[2]
            && d.getDate() == r[3] && d.getHours() == r[4]
            && d.getMinutes() == r[5] && d.getSeconds() == r[6]);
        if (num == 0) {
            return false;
        }
        return (num != 0);
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 是否日期类型
       * @description 是否日期类型
       * @url isDate(dateString)
       * @method $instance.isDate(dateString)
       * @param dateString 必选 Date|String 日期时间
       * @return boolean
       * @number 60  
       */
    isDate: function (dateString) {
        if (dateString == "")
            return true;
        // 年月日正则表达式
        var r = dateString.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) {
            return false;
        }
        var d = new Date(r[1], r[3] - 1, r[4]);
        let num = (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d
            .getDate() == r[4]);
        if (num == 0) {
            return false;
        }
        return (num != 0);
    },
    dateof: function (dt, type) {
        let result;
        if (!dt)
            return "";
        if (typeof dt == "string")
            dt = DateUtil.strToDate(dt);
        switch (type) {
            case "y":
                result = dt.getFullYear();
                break;
            case "m":
                result = dt.getMonth() + 1;
                break;
            case "min":
                result = dt.getMinutes();
                break;
            case "time":
                result = DateUtil.format("yyyy-MM-dd hh:mm:ss");
                break;
            case "date":
                result = DateUtil.format('yyyy-MM-dd');
                break;
            case "weekCn":
                result = dt.week();
                break;
            case "week":
                result = dt.getDay();
                break;
            case "weekInYear":
                var first = new Date(dt.getFullYear(), 0, 1);
                var n = parseInt("1065432".charAt(first.getDay()));
                n = dt.getTime() - first.getTime() - n * 24 * 60 * 60 * 1000;
                n = Math.ceil(n / (7 * 24 * 60 * 60 * 1000));
                result = first.getDay() != 1 ? (n + 1) : n;
                break;
            default:
                result = "";
        }
        return result;
    },
    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 字符转换指定日期类型
   * @description 字符转换指定日期类型
   * @url strFormatDate(strDate,strFormat)
   * @method $instance.strFormatDate(strDate,strFormat)
   * @param strDate 必选 String 日期时间
   * @param strFormat 必选 String 格式化类型
   * @return Date
   * @number 60  
   */
    strFormatDate: function (strDate, strFormat) {
        if (strDate == "" || strDate == null)
            return "";
        let d = DateUtil.strToDate(strDate);
        if (!strFormat)
            return d;
        return d.format(strFormat);
    },
    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 字符转换日期类型
   * @description 字符转换日期类型
   * @url strToDate(dataStr)
   * @method $instance.strToDate(dataStr)
   * @param dataStr 必选 String 日期时间
   * @return Date
   * @number 60  
   */
    strToDate: function (dataStr) {
        if (!dataStr)
            return "";
        if (dataStr && dataStr.constructor === Date) { // 2010.08.02
            // 已经是时间类型，就不过滤。
            return dataStr;
        }
        if (typeof dataStr == "string") {
            if (dataStr.indexOf('.') > -1) // 2010.07.13 08335 cai
                dataStr = dataStr.split('.')[0];
        }
        // 只有时间字符串 01521
        if (dataStr.indexOf("-") == -1 && dataStr.indexOf(".") == -1
            && dataStr.indexOf(":") != -1)
            dataStr = DateUtil.dateOf(new Date()) + " " + dataStr;

        var arr = dataStr.split(/[- :]/)
        if (dataStr != "" && arr.length == 1) { // 当：dataStr：1,返回：2010-01-01
            // 00:00:00
            console.log(dataStr + " Invalid Date")
            return "";
        }

        return new Date(Date.parse(dataStr));
    }
    ,
    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 获得季度的第一天
   * @description 获得季度的第一天
   * @url getQuarterStartDay(dataStr)
   * @method $instance.getQuarterStartDay(dataStr)
   * @param dataStr 必选 Date 日期时间
   * @return Date
   * @number 60  
   */
    getQuarterStart: function () {
        var now = new Date();
        var QuarterStartDate = '';
        if (now.getMonth() < 3) {
            QuarterStartDate = new Date(now.getFullYear(), 0, 1);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 2 && now.getMonth() < 6) {
            QuarterStartDate = new Date(now.getFullYear(), 3, 1);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 5 && now.getMonth() < 9) {
            QuarterStartDate = new Date(now.getFullYear(), 6, 1);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 8) {
            QuarterStartDate = new Date(now.getFullYear(), 9, 1);
            return this.format(QuarterStartDate, "yyyy-MM-dd");

        }
    },
    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 获得本季度的结束日期
   * @description 获得本季度的结束日期
   * @url getQuarterEndDate()
   * @method $instance.getQuarterEndDate()
   * @return Date
   * @number 60  
   */
    getQuarterEndDate: function () {
        var now = new Date();
        var QuarterStartDate = '';
        if (now.getMonth() < 3) {
            QuarterStartDate = new Date(now.getFullYear(), 2, 31);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 2 && now.getMonth() < 6) {
            QuarterStartDate = new Date(now.getFullYear(), 5, 30);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 5 && now.getMonth() < 9) {
            QuarterStartDate = new Date(now.getFullYear(), 8, 30);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        } else if (now.getMonth() > 8) {
            QuarterStartDate = new Date(now.getFullYear(), 11, 31);
            return this.format(QuarterStartDate, "yyyy-MM-dd");
        }
    },

    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 获得本年度的开始日期
   * @description 获得本年度的开始日期
   * @url getYearStartDate()
   * @method $instance.getYearStartDate()
   * @return Date
   * @number 60  
   */
    getYearStartDate: function () {
        var now = new Date();
        var yearFirstDay = new Date(now.getFullYear(), 0, 1);
        return this.format(yearFirstDay, "yyyy-MM-dd");
        //return yearFirstDay.format("yyyy-MM-dd");
    },

    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 获得本年度的结束日期
   * @description 获得本年度的结束日期
   * @url getYearEndDate()
   * @method $instance.getYearEndDate()
   * @return Date
   * @number 60  
   */
    getYearEndDate: function () {
        var now = new Date();
        var yearLastDay = new Date(now.getFullYear(), 11, 31);
        return this.format(yearLastDay, "yyyy-MM-dd");
        //return yearLastDay.format("yyyy-MM-dd");
    },
    /**
   * showdoc
  * @catalog API/工具/Date
   * @title 获得某月的天数
   * @description 获得某月的天数
   * @url getMonthDays(myMonth，myYear)
   * @method $instance.getMonthDays(myMonth，myYear)
   *  @param myMonth，myYear 必选 int 月份
   *  @param myMonth，myYear 必选 int 年份
   * @return Int
   * @number 60  
   */
    getMonthDays: function (myMonth, myYear) {
        if (myYear == undefined) {
            var now = new Date();
            myYear = now.getFullYear();
        }
        myMonth--;
        var d = new Date(myYear, myMonth, 1);
        d.setDate(d.getDate() + 32 - d.getDate());
        return (32 - d.getDate())
    },

    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获得本周的开始日期
       * @description 获得本周的开始日期
       * @url getWeekStartDate()
       * @method $instance.getWeekStartDate()
       * @return Date
       * @number 60  
       */
    getWeekStartDate: function () {
        var now = new Date();
        var weekStartDate = new Date(now.getFullYear(), now.getMonth(), now
            .getDate()
            - now.getDay());
        return this.format(weekStartDate, "yyyy-MM-dd");
    },

    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获得本周的结束日期
       * @description 获得本周的结束日期
       * @url getWeekEndDate()
       * @method $instance.getWeekEndDate()
       * @return Date
       * @number 60  
       */
    getWeekEndDate: function () {
        var now = new Date();
        var weekEndDate = new Date(now.getFullYear(), now.getMonth(), now
            .getDate()
            + (6 - now.getDay()));
        return this.format(weekEndDate, "yyyy-MM-dd");
        //return weekEndDate.format("yyyy-MM-dd");
    },

    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获得本月的开始日期
       * @description 获得本月的开始日期
       * @url getMonthStartDate()
       * @method $instance.getMonthStartDate()
       * @param dateVal 必选 Date|String 日期
       * @return Date
       * @number 60  
       */
    getMonthStartDate: function (dateVal) {
        var now = new Date();
        if (dateVal && typeof dateVal == "string")
            now = DateUtil.strToDate(dateVal);
        var monthStartDate = new Date(now.getFullYear(), now.getMonth(), 1);
        return this.format(monthStartDate, "yyyy-MM-dd");
        //monthStartDate.format("yyyy-MM-dd");
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获得本月的结束日期
       * @description 获得本月的结束日期
       * @url getMonthEndDate()
       * @method $instance.getMonthEndDate()
       * @return Date
       * @number 60  
       */
    getMonthEndDate: function (dateVal) {
        var now = new Date();

        if (dateVal && typeof dateVal == "string")
            now = DateUtil.strToDate(dateVal);

        let year = now.getFullYear();
        let month = now.getMonth();
        var tempDate = new Date(new Date(year, month + 1, 1).getTime() - 1000
            * 60 * 60 * 24)
        return this.format(tempDate, "yyyy-MM-dd");
        //return tempDate.format("yyyy-MM-dd");
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获当前时间
       * @description 获当前时间
       * @url now()
       * @method $instance.now(format)
       * @param format 可选 String 格式化
       * @return Date
       * @number 60  
       */
    now: function (format) {
        format = format || "yyyy-MM-dd hh:mm:ss";
        return this.format(new Date(), format);
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 获时间方案
       * @description 获时间方案
       * @url TimeScheme(name)
       * @method $instance.TimeScheme(name)
       * @param name 必选 String 方案名称
       * @return Date
       * @number 60  
       */
    TimeScheme: function (name) {
        var startTime = " 00:00:00到", endTime = " 23:59:59";
        switch (name) {
            case "today":
                return this.format(this.strToDate(this.now()), "yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

            case "yesterday":
                return this
                    .format(this.dateAdd("d", -1, this.now()),
                        "yyyy-MM-dd")
                    + startTime
                    + this.format(this.dateAdd("d", -1, this
                        .now()), "yyyy-MM-dd")
                    + endTime;

            case "week":
                return this.getWeekStartDate() + startTime
                    + this.getWeekEndDate() + endTime;

            case "month":
                return this.getMonthStartDate() + startTime
                    + this.getMonthEndDate() + endTime;

            case "quarter":
                return this.getQuarterStartDate() + startTime
                    + this.getQuarterEndDate() + endTime;

            case "year":
                return this.getYearStartDate() + startTime
                    + this.getYearEndDate() + endTime;

            case "days7":
                return this.format(this.dateAdd("d", -7, this.now())
                    , "yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

            case "days28":
                return this.format(this.dateAdd("d", -28, this.now())
                    , "yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

            case "days84":
                return this.dateAdd("d", -84, this.now())
                    .format("yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

            case "halfyear":
                return this.dateAdd("m", -6, this.now())
                    .format("yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

            case "oneyear":
                return this.format(this.dateAdd("y", -1, this.now())
                    , "yyyy-MM-dd")
                    + startTime
                    + this.format(this.strToDate(this.now()),
                        "yyyy-MM-dd") + endTime;

        }
    },
    /**
       * showdoc
      * @catalog API/工具/Date
       * @title 在日期中添加或者减去指定的时间间隔天数
       * @description 在日期中添加或者减去指定的时间间隔天数
       * @url dateAdd(datepart, number, dtDate)
       * @method $instance.dateAdd(datepart, number, dtDate)
       * @param datepart 必选 String 间隔类型
       * @param number 必选 Int 间隔数
       * @param dtDate 必选 Date 
       * @return Date
       * @number 60  
       */
    dateAdd: function (datepart, number, dtDate) {
        if (typeof dtDate == "string")
            dtDate = DateUtil.strToDate(dtDate);
        var date = new Date(dtDate);
        datepart = (datepart || 'd').toLowerCase();
        let diff = parseInt(number);
        let tempdate;
        switch (datepart) {
            case "y": // 年
                tempdate = date.setYear(date.getFullYear() + diff)
                break;
            case "q": // 季度
                tempdate = date.setMonth(date.getMonth() + (diff * 3))
                break;
            case "m": // 月
                var sYear = date.getFullYear();
                var sMonth = date.getMonth() + 1;
                var sDay = date.getDate();

                var eYear = sYear;
                var eMonth = sMonth + diff;
                var eDay = sDay;
                while (eMonth > 12) {
                    eYear++;
                    eMonth -= 12;
                }

                var eDate = new Date(eYear, eMonth - 1, eDay);

                while (eDate.getMonth() != eMonth - 1) {
                    eDay--;
                    eDate = new Date(eYear, eMonth - 1, eDay);
                }
                tempdate = eDate;
                break;
            case "d": // 天
                tempdate = date.setDate(date.getDate() + diff);
                break;
            case "h": // 时
                tempdate = date.setHours(date.getHours() + diff);
                break;
            case "mi": // 分
                tempdate = date.setMinutes(date.getMinutes() + diff);
                break;
            case "s": // 秒
                tempdate = date.setSeconds(date.getSeconds() + diff)
                break;
            default:
                tempdate = date.setDate(date.getDate() + diff);
                break;
        }
        return new Date(tempdate);
    }
}



