JS Convert date format

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.