JS formatted Date ("/date (1400046388387)/")

Source: Internet
Author: User

When the program asynchronously commits, and returns is the return JSON, the time that you receive in this JS is likely to be this way: "/date (1400046388387)/", this is a string.

Of course, you can't just show him on the page and format him: The method of collecting online is recorded here:

1. First convert the return value to JS date type

2, using the Format method of date formatted output (This format method is self-expanding)

var str = '/date (1400046388387)/'; var d = eval (' new ' + str.substr (1, str.length-2)); New Date () D.format ("Yyyy-mm-dd hh:mm:ss") Date.prototype.Format = function (FMT) {//author:meizz     var o = {        "m+ ": This.getmonth () + 1,//month         " d+ ": this.getdate (),//day         " H + ": this.gethours (),//hour         " m+ ": this.getminutes (), Sub         "s+": This.getseconds (),//sec         "q+": Math.floor ((This.getmonth () + 3)/3),//quarterly         "s": This.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;}

If it is not JSON return, preferably in the background with C # ToString ("Yyyy-mm-dd hh:mm:ss") way to transfer to the foreground, without JS conversion.

JS formatted Date ("/date (1400046388387)/")

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.