首页 > Web开发 > 详细

js 时间日期函数

时间:2018-11-07 15:05:35      阅读:155      评论:0      收藏:0      [点我收藏+]

忘记从哪里拷贝过来的了,侵删

 1 Date.prototype.format = function (format) {
 2             var date = {
 3                 "M+": this.getMonth() + 1,
 4                 "d+": this.getDate(),
 5                 "h+": this.getHours(),
 6                 "m+": this.getMinutes(),
 7                 "s+": this.getSeconds(),
 8                 "q+": Math.floor((this.getMonth() + 3) / 3),
 9                 "S+": this.getMilliseconds()
10             };
11              
12             if (/(y+)/i.test(format)) {
13                 format = format.replace(RegExp.$1, (this.getFullYear() + ‘‘).substr(4 - RegExp.$1.length));
14             }
15          
16             for (var k in date) {
17                 if (new RegExp("(" + k + ")").test(format)) {
18                   format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
19                 }
20             }
21              
22             return format;
23         }

使用时 new Date(xx).format("yyyy-MM-dd hh:mm:ss")即可

 

js 时间日期函数

原文:https://www.cnblogs.com/tele-share/p/9922450.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!