How to handle json DateTime returned from WCF Data Services (OData)

前端 未结 8 809
情书的邮戳
情书的邮戳 2020-12-01 11:19

I believe I am missing something obvious here. When I request a JSON response from an OData service I get a different result for the DateTime properties than I do when I req

8条回答
  •  隐瞒了意图╮
    2020-12-01 11:24

    This should work just fine:

    var date = new Date(parseInt(jsonDate.substr(6)));
    

    The substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end.

    For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:

    var date = new Date(jsonDate); //no ugly parsing needed; full timezone support
    

    This was already fixed and discussed that a look at this previous post

提交回复
热议问题