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