zoukankan      html  css  js  c++  java
  • 日期格式转换以及会员期限一个月这一个月是怎么算的?

    问题:例如,开通某一账号,开通日期为: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;
            }
    },

      

    我一路向北,离开有你的季节...
  • 相关阅读:
    StackExchange.Redis 使用 (一)
    委托的一个小问题
    MemberwishClone学习
    类的内容学习
    类的学习
    构造函数学习
    C# 重新筑基-从头开始
    C语言入门:结构体+文件的应用
    C语言入门:结构体的概要
    C语言入门:指针的概要
  • 原文地址:https://www.cnblogs.com/dancer0321/p/14813519.html
Copyright © 2011-2022 走看看