The UTC format time must be familiar to everyone. How can we convert it to a local format? In fact, it is very simple. The following method will help you implement this idea.
The Code is as follows:
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;
}
Var TempDate = new Date ();
TempDate. toLocaleDateString () // September 4, 2013
TempDate. format ("yyyy-MM-dd") // 2013-09-04