jquery - Comment formater une date Microsoft JSON

Mots clés : jqueryasp.netajaxjsonjquery

meilleur 4 Réponses jquery - Comment formater une date Microsoft JSON

vote vote

99

var date = new Date(parseInt(jsonDate.substr(6))); 
var date = new Date(jsonDate); //no ugly parsing needed; full timezone support 
vote vote

85

var date = eval(jsonDate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)")); 
vote vote

77

string jsonText = JsonConvert.SerializeObject(p, new IsoDateTimeConverter()); 
"fieldName": "2009-04-12T20:44:55" 
function isoDateReviver(value) {   if (typeof value === 'string') {     var a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)(?:([\+-])(\d{2})\:(\d{2}))?Z?$/.exec(value);       if (a) {         var utcMilliseconds = Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]);         return new Date(utcMilliseconds);       }   }   return value; } 
$("<span />").text(isoDateReviver(item.fieldName).toLocaleString()).appendTo("#" + divName); 
vote vote

66

/Date(1224043200000)/   
[OperationContract] [WebInvoke(     RequestFormat = WebMessageFormat.Json,     ResponseFormat = WebMessageFormat.Json,     BodyStyle = WebMessageBodyStyle.WrappedRequest     )] ApptVisitLinkInfo GetCurrentLinkInfo( int appointmentsId ); 
public class ApptVisitLinkInfo {     string Field1 { get; set; }     DateTime Field2 { get; set; }     ... } 
/Date(1224043200000-0600)/ 
/\/Date\((.*?)\)\//gi 
replace(/\/Date\((.*?)\)\//gi, "new Date($1)"); 

Questions similaires