JavaScript格式化日期輸出
阿新 • • 發佈:2017-08-22
javascrip img tab solid round -m min time lac
JavaScript Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<script> window.onload = function(){ Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+" "H+": this.getHours(), //小時 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == return fmt; } var currenttime1 = new Date().Format("yyyy-MM-ddTHH:mm:ss"); var pselstart = document.getElementById("starttime"); pselstart.value = currenttime1; var currenttime2 = new Date().Format("yyyy-MM-ddTHH:mm:ss"); var pselend = document.getElementById("endtime"); pselend.value = currenttime2; } </script> |
JavaScript格式化日期輸出