date.prototype.format = function (FMT) {//author:meizz var o = {"m+": This.getmonth () + 1,//month "d+": this.getdate (),//day "H +": this.gethours (),//Hour "m+": this.getmin Utes (),//min "s+": This.getseconds (),//sec "q+": Math.floor ((This.getmonth () + 3)/3),//quarterly "s": th Is.getmilliseconds ()//msec}; 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]): (("XX" + o[k]). substr (("" + O[k]).)); return FMT;} function Daysjian () {var date = new Date (' 2006-7-1 8:9:4.18 ');//Gets the current time Date.setdate (Date.getdate ()-1);//Set days-1 days var time = date. Format ("Yyyy-mm-dd"); return time;} Console.log (Daysjian ());
Console.log ("=====================")
Console.log (New Date (1234567897789). Format ("Yyyy-mm-dd hh:mm:ss"))
JS date format time, gets the current time, the day before