ASP.NET Parse DateTime result from ajax call to javascript date

后端 未结 4 1451
情书的邮戳
情书的邮戳 2020-12-01 18:42

Introduction:

I have a WebMethod on my ASP.NET page which returns a Person object. One of the fields is Birthday

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 19:11

    You could try this:

       _$.ajax({
            url: 'Default.aspx/GetPerson',
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                console.log(JSON.stringify(data.d));
                var src = data.d.Birthday;
                //Remove all non-numeric (except the plus)
                src = src.replace(/[^0-9 +]/g, ''); 
                //Create date
                var birthDate = new Date(parseInt(src));
                self.html(birthDate);
            }
        });
    

    JSFiddle

提交回复
热议问题