The conversion of JSON's datatime format in JavaScript

Source: Internet
Author: User

1         //Val is the data of the DateTime type of C # that is directly serialized by JSON2         functionFormattime (val) {3             varRe =/-?\d+/;4             varm =Re.exec (val);5             varD =NewDate (parseint (m[0]));6             //return date as "2012-02-13-09:09:09" format7             returnD.format ("Yyyy-mm-dd hh:mm:ss");8         }9 TenDate.prototype.format =function(format) One         { A             varo = { -"m+": This. GetMonth () + 1,//Month -"D+": This. GetDate (),// Day the"H +": This. GetHours (),//Hour -"m+": This. getminutes (),//minute -"S+": This. getseconds (),//Second -"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarter +"S": This. Getmilliseconds ()//Millisecond -             } +             if(/(y+)/.test (format)) format = Format.replace (regexp.$1, A( This. getFullYear () + ""). substr (4-regexp.$1. length)); at              for(varKinchOif(NewRegExp ("(" + K + ")"). Test (format)) -Format = Format.replace (regexp.$1, -Regexp.$1.length = = 1?O[k]: -("XX" + o[k]). substr ("" +O[k]) (length)); -             returnformat; -};

Used primarily for background data return, time format conversion

The complete code is as follows

1     //Real-time search by book number2$(function () {3$ ("#BookId"). Bind ("Input Onpropertychange",function () {4             varValue = $ ("#BookId"). Val ();5 $.ajax ({6URL: '/bookadmin/return_upbookinfo ',7Type: ' Post ',8 data: {9' BookId ': $ ("#BookId"). Val ()Ten                 }, OneDataType: ' JSON ', ASuccessfunction(data) { -                     if(Data = =NULL) { -$ ("#BookName"). attr ("Value", "" "); the$ ("#Author"). attr ("Value", "" "); -$ ("#Translator"). attr ("Value", "" "); -$ ("#Price"). attr ("Value", "" "); -$ ("#ISBNCode"). attr ("Value", "" "); +$ ("#PublishCompany"). attr ("Value", "" "); -$ ("#ComeUpTime"). attr ("Value", "" "); +$ ("#State"). attr ("Value", "" "); A$ ("#EnteringMen"). attr ("Value", "" "); at                     } -                     Else { -$ ("#BookName"). attr ("value"), data. BookName); -$ ("#Author"). attr ("value"), data. Author); -$ ("#Translator"). attr ("value"), data. Translator); -$ ("#Price"). attr ("value"), data. Price); in$ ("#ISBNCode"). attr ("value"), data. Isbncode); -$ ("#PublishCompany"). attr ("value"), data. Publishcompany); to  +$ ("#ComeUpTime"). attr ("value"), Formattime (Data.comeuptime)); -$ ("#State"). attr ("value"), data. State); the$ ("#EnteringMen"). attr ("value"), data. Enteringmen); *                     } $                 },Panax NotoginsengErrorfunction(data) { -                 } the             }) +         }); A  the         //Val is the data of the DateTime type of C # that is directly serialized by JSON +         functionFormattime (val) { -             varRe =/-?\d+/; $             varm =Re.exec (val); $             varD =NewDate (parseint (m[0])); -             //return date as "2012-02-13-09:09:09" format -             returnD.format ("Yyyy-mm-dd hh:mm:ss"); the         } - WuyiDate.prototype.format =function(format)//Author:meizz the         { -             varn \ { Wu"m+": This. GetMonth () + 1,//Month -"D+": This. GetDate (),// Day About"H +": This. GetHours (),//Hour $"m+": This. getminutes (),//minute -"S+": This. getseconds (),//Second -"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarter -"S": This. Getmilliseconds ()//Millisecond A             } +             if(/(y+)/.test (format)) format = Format.replace (regexp.$1, the( This. getFullYear () + ""). substr (4-regexp.$1. length)); -              for(varKinchOif(NewRegExp ("(" + K + ")"). Test (format)) $Format = Format.replace (regexp.$1, theRegexp.$1.length = = 1?O[k]: the("XX" + o[k]). substr ("" +O[k]) (length)); the             returnformat; the         }; -});
View Code

    

The conversion of JSON's datatime format in JavaScript

Related Article

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.