zoukankan      html  css  js  c++  java
  • 某个时间周期的头天或尾天

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

    
    //本周的第一天
    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();//上个月的最
    }
    
    
  • 相关阅读:
    字节流
    类File
    try...catch语句
    Collections工具类
    类TreeMap
    类HashMap
    类TreeSet
    jquery 选择器加变量
    bootstrap 事件shown.bs.modal用于监听并执行你自己的代码【写hostmanger关联部门遇到的问题及解决方法】
    jquery中append、prepend, before和after方法的区别(一)
  • 原文地址:https://www.cnblogs.com/qixidi/p/10287467.html
Copyright © 2011-2022 走看看