Sometimes the project will use the JS date format, because the format returned by date () is not what we need, date () return format: Thu Mar12:00:00 gmt+0800(China Standard Time) and we need this format:2015-3-19 12:00:00unless the time format is processed in the background, then it is displayed directly on the page. How to format the date value with JS? 1.js method return Value: 2015-03-19[JavaScript] view plaincopy on code to see a snippet derived from my Code slicevarFormatDate =function(date) {vary =date.getfullyear (); varm = date.getmonth () + 1; M= M < 10? ' 0 ' +m:m; varD =date.getdate (); D= d < 10? (' 0 ' +d): D; returnY + '-' + M + '-' +D; }; 2.js method return value: 2015-03-19 12:00[JavaScript] view plaincopy on code to see a snippet derived from my Code slicevarFormatDateTime =function(date) {vary =date.getfullyear (); varm = date.getmonth () + 1; M= M < 10? (' 0 ' +m): M; varD =date.getdate (); D= d < 10? (' 0 ' +d): D; varh =date.gethours (); varminute =date.getminutes (); Minute= Minute < 10? (' 0 ' +minute): minute; returnY + '-' + M + '-' + d+ ' +h+ ': ' +minute; }; Called: FormatDate (Date ()) FormatDate (date ()) how to-03-12 12:00Convert to Standard Time ()? Thu Mar12:00:00 gmt+0800(China Standard Time) JS method return value: Thu Mar12:00:00 gmt+0800(China Standard Time) [JavaScript] view plaincopy on code to see a snippet derived from my Code slicevarParserdate =function(date) {vart =Date.parse (Date); if(!IsNaN (t)) { return NewDate (Date.parse (Date.replace (/-/g, "/"))); } Else { return NewDate (); } }; Call: Parserdate ("2015-03-19 12::00:00")
JS Convert date format