This article mainly introduces the javascript date formatting method. The example summarizes the JavaScript formatting techniques for date and time, which has some reference value, you can refer to the examples in this article to summarize the javascript date formatting method. We will share this with you for your reference. The details are as follows:
Prototype:
Date. prototype. format = function (fmt) {// author: meizz var o = {"M +": this. getMonth () + 1, // month "d +": this. getDate (), // Day "h +": this. getHours (), // Hour "m +": this. getMinutes (), // minute "s +": this. getSeconds (), // second "q +": Math. floor (this. getMonth () + 3)/3), // quarter "S": this. getMilliseconds () // millisecond}; 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 = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length); return fmt ;}
Put this code in script and script.
Then, use the following statement when calling:
The Code is as follows:
New Date (). Format ("yyyy-MM-dd hh: mm: ss ")
For details, refer to the previous Article Date format (js Date formatting) method summary in javascript.
In addition, the function for obtaining the current date is as follows: