JavaScriptSerializer is subtracting one day from date

前端 未结 3 1821
天涯浪人
天涯浪人 2020-12-10 01:18

I am using JavaScriptSerializer for serializing DateTime, but when I deserialize it show one day less from the date it get serialize:

Here is test:

3条回答
  •  臣服心动
    2020-12-10 01:56

    I had the same problem and solved it by using

    Newtonsoft.Json.JsonConvert.SerializeObject()
    

    instead of

    new System.Web.Script.Serialization.JavaScriptSerializer().Serialize().
    

    The latter call stores your DateTime converted to some random timezone (GMT+0 seems to be hardcoded).

提交回复
热议问题