继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

前端使用js格式化日期

慕莱坞5349459
关注TA
已关注
手记 1
粉丝 0
获赞 2
formatCSTDate:function(strDate,format){
        return inviteRecList.formatDate(new Date(strDate.time),format);
    },
    formatDate:function(date,format){
         var paddNum = function(num){
              num += "";
              return num.replace(/^(\d)$/,"0$1");
            }
        //指定格式字符
        var cfg = {
           yyyy : date.getFullYear() //年 : 4位
          ,yy : date.getFullYear().toString().substring(2)//年 : 2位
          ,M  : date.getMonth() + 1  //月 : 如果1位的时候不补0
          ,MM : paddNum(date.getMonth() + 1) //月 : 如果1位的时候补0
          ,d  : date.getDate()    
          ,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
          ,hh : paddNum(date.getHours())//时:如果1位的时候补0
          ,mm : paddNum(date.getMinutes())//分:如果1位的时候补0  
          ,ss : paddNum(date.getSeconds())//秒:如果1位的时候补0    
        }
        format || (format = "yyyy-MM-dd hh:mm:ss");
        return format.replace(/([a-z])(\1)*/ig,function(m){return cfg[m];});
    }
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP