首页/javascript外包/js 时间戳格式化 格式为 yyyy-mm-dd hh:MM:ss

js 时间戳格式化 格式为 yyyy-mm-dd hh:MM:ss

发布-xiaoming | 浏览量-

js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss

Date.prototype.format = function (format) {
           var args = {
               "M+": this.getMonth() + 1,
               "d+": this.getDate(),
               "h+": this.getHours(),
               "m+": this.getMinutes(),
               "s+": this.getSeconds(),
               "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
               "S": this.getMilliseconds()
           };
           if (/(y+)/.test(format))
               format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
           for (var i in args) {
               var n = args[i];
               if (new RegExp("(" + i + ")").test(format))
                   format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
           }
           return format;
       };

调用方法

alert(new Date().format("yyyy-MM-dd hh:mm:ss:S"));

alert(new Date().format("yyyy-MM-dd hh:mm:ss"));

原文地址:http://www.35ui.cn/post/20161010474.html

标签时间戳格式化

上一条: js金额格式化(数字分割)
下一条: 纯CSS实现箭头、气泡让提示功能具有三角形图标

或许你还对下面的文章感兴趣