javascript Default time format We don't normally use it, so we need to format it, and here's what I've summed up about the JavaScript time formatting method
Many times, we can use the built-in methods of the Date object in JavaScript to format it, such as: code as follows: var d = new Date (); Console.log (d); Output: Mon Nov 2013 21:50:33 gmt+0800 (China Standard Time) Console.log (d.todatestring ()); Date string, Output: Mon Nov 2013 Console.log (d.togmtstring ()); GMT, Output: Mon, Nov 2013 14:03:05 GMT Console.log (d.toisostring ()); International Standard Organization (ISO) format, output: 2013-11-04t14:03:05.420z console.log (D.tojson ()); Output: 2013-11-04t14:03:05.420z console.log (D.tolocaledatestring ()); Convert to local date format, depending on the environment, output: November 4, 2013 Console.log (D.tolocalestring ()); Convert to local date and time format, depending on the environment, output: November 4, 2013 afternoon 10:03:05 Console.log (d.tolocaletimestring ()); Convert to local time format, depending on the environment, output: PM 10:03:05 console.log (d.tostring ()); Convert to String, output: Mon Nov 2013 22:03:05 gmt+0800 (China Standard Time) Console.log (d.totimestring ()); Convert to time string, output: 22:03:05 gmt+0800 (China Standard Time) Console.log (d.toutcstring ()); Convert to World time, output: Mon, Nov 2013 14:03:05 GMT If the above method does not meet our requirements, we can also customize the function to format the time, such as: code as follows: Date.prototype.format = function (format) { var date = { &nbsP "m+": This.getmonth () + 1, "d+": this. GetDate (), "h+": this.gethours (), &NBS P "m+": this.getminutes () "s+": This.getseconds (), &N Bsp "q+": Math.floor (This.getmonth () + 3)/3), "S+": This.getmilliseconds () }; if (/(y+)/i.test (format)) { format = Format.re Place (Regexp.$1, (this.getfullyear () + "). substr (4-regexp.$1.length)); for (var k in date) { &N Bsp if (new RegExp ("+ K +")). Test (format) { &NBSp;format = Format.replace (regexp.$1, regexp.$1.length = 1 ? Date[k]: ("+ date[k]"). substr (("" "+ date[k]). length);   return format; var d = new Date (). Format (' Yyyy-mm-dd '); Console.log (d); 2013-11-04