某个时间周期的头天或尾天

某个时间周期的头天或尾天


//本周的第一天
weekFirstDay: function (date) {
    var Nowdate = new Date(date);
    var WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
    M = Number(WeekFirstDay.getMonth()) + 1
    M = M < 10 ? "0" + M : M;
    return WeekFirstDay.getFullYear() + "-" + M + "-" + WeekFirstDay.getDate();
},
//本周的最后一天
weekLastDay: function (date) {
    var Nowdate = new Date(date);
    var WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
    var WeekLastDay = new Date((WeekFirstDay / 1000 + 6 * 86400) * 1000);
    M = Number(WeekLastDay.getMonth()) + 1
    M = M < 10 ? "0" + M : M;
    return WeekLastDay.getFullYear() + "-" + M + "-" + WeekLastDay.getDate();
},
//本月第一天
monthFirstDay: function () {
    var Nowdate = new Date();
    var MonthFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth(), 1);
    M = Number(MonthFirstDay.getMonth()) + 1
    M = M < 10 ? "0" + M : M;
    return MonthFirstDay.getFullYear() + "-" + M + "-" + MonthFirstDay.getDate();
},
//本月最后一天
monthLastDay: function () {
    var Nowdate = new Date();
    var MonthNextFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth() + 1, 1);
    var MonthLastDay = new Date(MonthNextFirstDay - 86400000);
    M = Number(MonthLastDay.getMonth()) + 1
    M = M < 10 ? "0" + M : M;
    return MonthLastDay.getFullYear() + "-" + M + "-" + MonthLastDay.getDate();
},
//上个月第一天
upMonthFirstDay: function () {
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    var month = nowdays.getMonth();
    if (month == 0) {
        month = 12;
        year = year - 1;
    }
    if (month < 10) {
        month = "0" + month;
    }
    return year + "-" + month + "-" + "01";//上个月的第一天
},
//上个月最后一天
upMonthLastDay: function () {
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    var month = nowdays.getMonth();
    if (month == 0) {
        month = 12;
        year = year - 1;
    }
    if (month < 10) {
        month = "0" + month;
    }
    //return year + "-" + month + "-" + "01";//上个月的第一天
    var myDate = new Date(year, month, 0);
    return year + "-" + month + "-" + myDate.getDate();//上个月的最
}

posted @ 2019-01-18 14:28  栖息地  阅读(167)  评论(0编辑  收藏  举报