加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

格式化时间

发布时间:2020-12-15 07:18:46 所属栏目:Java 来源:网络整理
导读:1 script 2 Date.prototype.Format = function (fmt) { // author: meizz 3 var o = { 4 "M+": this .getMonth() + 1, // 月份 5 "d+": this .getDate(), // 日 6 "h+": this .getHours(), // 小时 7 "m+": this .getMinutes(), // 分 8 "s+": this .getSeco
 1 <script>
 2     Date.prototype.Format = function (fmt) { //author: meizz
 3     var o = {
 4       "M+": this.getMonth() + 1,//月份
 5       "d+": this.getDate(),//
 6       "h+": this.getHours(),//小时
 7       "m+": this.getMinutes(),//
 8       "s+": this.getSeconds(),//
 9       "q+": Math.floor((this.getMonth() + 3) / 3),//季度
10       "S": this.getMilliseconds() //毫秒
11     };
12     if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length));
13     for (var k in o)
14       if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1,(RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
15     return fmt;
16   }
17   var  submitTime = new Date().Format("yyyy-MM-dd hh:mm:ss")
18   console.log(submitTime);
19 </script>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读