How to parse ASP.NET JSON Date format with GWT

后端 未结 2 1575
面向向阳花
面向向阳花 2021-01-19 04:14

ASP.NET JSON serialize DateTime to the following format \"/Date(1251877601000)/\". Pls, help parse this string into the java(GWT) Date object.

At this time the solut

2条回答
  •  日久生厌
    2021-01-19 04:37

    function FixJsonDates(data) {
    
            //microsoft script service perform the following to fix the dates.
            //json date:\/Date(1317307437667-0400)\/"
            //javasccript format required: new Date(1317307437667-0400)
    
            //copied from micrsoft generated fiel.
           var _dateRegEx = new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)(?:[a-zA-Z]|(?:\\+|-)[0-9]{4})?\\)\\\\/\\"', 'g');
           var exp = data.replace(_dateRegEx, "$1new Date($2)");
    
    
           return eval(exp);
       }
    

提交回复
热议问题