Javascript format the JSON date. The javascriptjson date

Source: Internet
Author: User

Javascript format the JSON date. The javascriptjson date

The following is the sample code.

First effect:

/// Function jsonDateFormat (jsonDate) {// convert the json date format to the normal format. try {var Date = new date (parseInt (jsonDate. replace ("/Date (",""). replace (")/", ""), 10); var month = date. getMonth () + 1 <10? "0" + (date. getMonth () + 1): date. getMonth () + 1; var day = date. getDate () <10? "0" + date. getDate (): date. getDate (); return date. getFullYear () + "-" + month + "-" + day;} catch (ex) {return "";}}

Second effect:

/// Function jsonDateFormat (jsonDate) {// convert the json date format to the normal format. try {var Date = new date (parseInt (jsonDate. replace ("/Date (",""). replace (")/", ""), 10); var month = date. getMonth () + 1 <10? "0" + (date. getMonth () + 1): date. getMonth () + 1; var day = date. getDate () <10? "0" + date. getDate (): date. getDate (); var hours = date. getHours (); var minutes = date. getMinutes (); var seconds = date. getSeconds (); var milliseconds = date. getMilliseconds (); return date. getFullYear () + "-" + month + "-" + day + "" + hours + ":" + minutes + ":" + seconds + ". "+ milliseconds;} catch (ex) {return "";}}

Summary

The above is all the content formatted by Javascript to the JSON date. Although the function is very small, it is very practical. I hope this will help you in your learning work.

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.