2011-06-16 115 views
1

我將某些屬性作爲JSON字符串傳遞給客戶端。但是,日期不以正確的格式打印。它顯示出一些數字,如1644506800。這是我做過什麼日期格式打印不正確

 var query = (from n in CDC.NCDCPoints 
       where n.EVENT_TYPE_ID == et && n.BeginDate == b && n.EndDate == e 
       select new { 
        n.EVENT_TYPE_ID, 
       begindate1 = n.BeginDate, 
       n.EndDate, 
       n.BeginLAT, 
       n.BeginLONG, 
       n.EndLAT, 
       n.EndLONG}); 


    if (query.Any()) 
    { 
     return new JavaScriptSerializer().Serialize(query.ToList()); 
    } 

jQuery中,

 $.ajax({ 
      type: "POST", url: "Data.aspx/CheckInsertRecord", 
      data: "{EventType:'" + eventtype + "',BeginDate:'" + begindate + "'," + 
        "EndDate:'" + enddate+"' }", 
      contentType: "application/json; charset=utf-8", dataType: "json", 
      success: function (msg) { 
     alert(msg.d); 

      var data = $.parseJSON(msg.d); 
      alert("A record of this event already exists in the database.\n" +msg.d+"."); 


      } 
     }); 

所以u能告訴我如何得到正確格式的日期?

回答

0

,你將有你打印

+0

我需要做的是在客戶端。那麼,你是否知道我可以使用反序列化的任何默認函數 – 2011-06-16 16:13:07

+0

我們可以看到你的一些客戶端代碼? – harryovers 2011-06-16 16:14:58

+0

我更新了代碼。 – 2011-06-16 16:16:07

0

的JavaScriptSerializer串行化Unix時間日期時間值之前,反序列化的日期,所以你必須是整數值反序列化到一個日期第一。你可以簡單地使用新的Date()做到這一點:

var data = $.parseJSON(msg.d); 
var deserializedDate = new Date(parseInt(data.BeginDate.substr(6)));