希望明天越|

张尊娟

园龄:5年3个月粉丝:31关注:1

时间跨度为一个月


 var dateObj = this.getLastMonth();
    this.dateTime = [new Date(dateObj.last).Format("yyyyMMdd"), new Date(dateObj.now).Format("yyyyMMdd")];
getLastMonth() {
            var now = new Date();
            var year = now.getFullYear();//getYear()+1900=getFullYear()
            var month = now.getMonth() + 1;//0-11表示1-12月
            var day = now.getDate();
            var dateObj = {};
            if (parseInt(month) < 10) {
                month = "0" + month;
            }
            if (parseInt(day) < 10) {
                day = "0" + day;
            }

            dateObj.now = year + '-' + month + '-' + day;

            if (parseInt(month) == 1) {//如果是1月份,则取上一年的12月份
                dateObj.last = (parseInt(year) - 1) + '-12-' + day;
                return dateObj;
            }

            var preSize = new Date(year, parseInt(month) - 1, 0).getDate();//上月总天数
            if (preSize < parseInt(day)) {//上月总天数<本月日期,比如3月的30日,在2月中没有30
                dateObj.last = year + '-' + month + '-01';
                return dateObj;
            }

            if (parseInt(month) <= 10) {
                dateObj.last = year + '-0' + (parseInt(month) - 1) + '-' + day;
                return dateObj;
            } else {
                dateObj.last = year + '-' + (parseInt(month) - 1) + '-' + day;
                return dateObj;
            }
        },

本文作者:张尊娟

本文链接:https://www.cnblogs.com/wszzj/p/17980424

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   张尊娟  阅读(12)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起