日期格式转换以及会员期限一个月这一个月是怎么算的?

问题:例如,开通某一账号,开通日期为:2021-01-31 08:13:05,一个月后到期,请问一个月之后到底是哪天?

     是2月31日还是2月28还是哪天?转换之后的格式为怎样  需要怎么处理?

 

  看代码:

  

  看效果:

  

 

  总结:

  这里可以看到:

  1、在指定的时间上加一个月,其实就是加了30天,不管本月是28天还是31天。

  2、加完一个月后时间格式变成了中国标准时间格式。

  这显然不是我们想要的结果,所以我们又调用自定义方法转换了下格式。至此,这个问题结束。

  源码:

  

created(){
        var date = new Date('2021-01-31 08:13:05');
        var newDate = new Date(date.setMonth(date.getMonth()+1));

        console.log("newDate------------:",newDate)
        console.log("newDate------------:",newDate.Format("yyyy-MM-dd hh:mm:ss.S q"))
        console.log("newDate------------:",newDate.Format("yyyy-MM-dd"))
        console.log("newDate------------:",newDate.Format("yyyy-M-d h:m:s.S q"))
        console.log("newDate------------:",newDate.Format("yyyy-M-d"))
        

        
        Date.prototype.Format = function (fmt) { //author: meizz 
            var o = {
                "M+": this.getMonth() + 1, //月份 
                "d+": this.getDate(), //
                "h+": this.getHours(), //小时 
                "m+": this.getMinutes(), //
                "s+": this.getSeconds(), //
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
                "S": this.getMilliseconds() //毫秒 
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
},

 

 

 

  

 

posted @ 2021-05-26 15:03  再见小猴子  阅读(451)  评论(0编辑  收藏  举报