[英]Deserializing JSON dates timezone-less
I have a problem that is breaking my head since yesterday and don't know how to deal with it. 我有一个问题,从昨天开始就打破了我的脑袋,不知道如何处理它。
The code in client side for the alert is this: 客户端的警报代码如下:
// transaction json model
var jsonTransaction = @(Html.Raw(Json.Encode(this.Model.Transaction)));
alert(new Date(parseInt(jsonTransaction.Date.substr(6))));
This is the code for deserializing: 这是反序列化的代码:
public JsonResult SaveBill(string jsonTransaction, string jsonTranDetails)
{
_appState = this.AppState;
JsonResult returnVal = returnVal = Json(
new { Success = true }
);
var transaction = JsonConvert.DeserializeObject<BillTransaction>(jsonTransaction, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
Any clue on how to solve this issue with dates, I should get the same date because I didn't change anything. 关于如何用日期解决这个问题的任何线索,我应该得到相同的日期,因为我没有改变任何东西。 Hope someone can guide me for a solution.
希望有人可以指导我寻求解决方案。
Thanks in advance. 提前致谢。
Java script use universal time when it parse the date as currentdate = new Date(123232) so when you send date to client convert it to ISO date such as make sure the date is in UTC before convering it to strong . Java脚本在将日期解析为currentdate = new Date(123232)时使用通用时间,因此当您向客户端发送日期时将其转换为ISO日期,例如确保日期为UTC,然后再将其转换为strong。
return String.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", dt);
bty I already created JSON Converted to override any date serialization to client side to use the above function . 我已经创建了JSON Converted来覆盖任何日期序列化到客户端以使用上面的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.