日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取当前日期时间并格式化 - 常见格式

發(fā)布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取当前日期时间并格式化 - 常见格式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
獲取系統(tǒng)當前日期時間的方法: 1 //獲取系統(tǒng)當前日期時間 2 Date.prototype.format = function (format) { 3 var o = { 4 "M+": this.getMonth() + 1, //month 5 "d+": this.getDate(), //day 6 "h+": this.getHours(), //hour 7 "m+": this.getMinutes(), //minute 8 "s+": this.getSeconds(), //second 9 "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 10 "S": this.getMilliseconds() //millisecond 11 }; 12 13 if (/(y+)/.test(format)) { 14 format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 15 } 16 17 for (var k in o) { 18 if (new RegExp("(" + k + ")").test(format)) { 19 format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); 20 } 21 } 22 return format; 23 }

使用方法1:

var now = new Date(); var nowStr = now.format("yyyy-MM-dd hh:mm:ss");

使用方法2:

var testDate = new Date(); var testStr = testDate.format("yyyy年MM月dd日hh小時mm分ss秒"); console.log(nowStr); console.log(testStr);

使用方法3:

console.log(new Date().format("yyyy年MM月dd日")); console.log(new Date().format("MM/dd/yyyy")); console.log(new Date().format("yyyyMMdd")); console.log(new Date().format("yyyy-MM-dd hh:mm:ss")); light7 框架使用日期時間模塊,對其限制時間做小為當前時間: $(function () {$(document).on("pageInit", function () {$('input[name="newSignDate"]').datetimePicker({toolbarTemplate: '<header class="bar bar-nav">\<button class="button button-link pull-right close-picker">確定</button>\<h1 class="title">選擇日期和時間</h1>\</header>'}).val(function () {return new Date().format("yyyy-MM-dd hh:mm:ss");}).bind('change', function () {var _date = new Date().format("yyyy-MM-dd hh:mm:ss");console.log($(this).val());if ($(this).val() <= _date) {$.alert("簽收時間必須大于當前時間")}})});$.init(); })

轉(zhuǎn)載于:https://www.cnblogs.com/myclovers/p/5394722.html

總結(jié)

以上是生活随笔為你收集整理的获取当前日期时间并格式化 - 常见格式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。