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;
            }
    },

      

    我一路向北,离开有你的季节...
  • 相关阅读:
    宁泽涛世锦赛夺冠
    iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
    在xcode里面如何利用instrument
    Xcode 中搜索任何条件文本
    十大算法
    Object c中的alloc和init问题
    My97DaePicker 用js实现文本框日期相减求天数
    js 取消listbox选中的项
    C# OR/Mapping 数据处理模式学习
    ASP.NET实现列表页连接查询 拼接sql语句 绑定grivdView
  • 原文地址:https://www.cnblogs.com/dancer0321/p/14813519.html
Copyright © 2011-2022 走看看