How to convert JavascriptSerializer serialized DateTime string to Javascript Date object

后端 未结 4 2008
别那么骄傲
别那么骄傲 2021-02-07 11:35

After serializing an object with DateTime field with JavaScriptSerializer, I see that the DateTime field looks like this:

         


        
4条回答
  •  被撕碎了的回忆
    2021-02-07 11:58

    var obj = { EffectiveFrom: "/Date(1355496152000)/" };
    
    //parse the Date value and replace the property value with Date object:
    
    var dateValue = parseInt(obj.EffectiveFrom.replace(/\/Date\((\d+)\)\//g, "$1"));
    obj.EffectiveFrom = new Date(dateValue);
    

提交回复
热议问题