In javascript, newDate () is a time value in the international time format, which is inconvenient for us to use Chinese characters, it is also difficult to see, so we need to format the date and time in javascript.
Script Date. prototype. format = function (format) {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 (format) format = format. replace (RegExp. $1, (this. getFullYear () +" "). Substr (4-RegExp. $1. length); for (var k in o) if (new RegExp ("(" + k + ")"). test (format) format = format. replace (RegExp. $1, RegExp. $1. length = 1? O [k]: ("00" + o [k]). substr ("" + o [k]). length); return format;} // call the method var t = new Date (); document. write ("before formatting:" + t + "<br>"); t = new Date (). format ("yyyy-MM-dd hh: mm: ss"); document. write ("formatted:" + t); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Javascript format date and time function _ time and date _ script house
Http://www.jb51.net/article/14753.htm