.NET WebService JSON Date in ISO-8601 Format

I call the .net asmx webservice, which returns multiple fields. One of the fields in the date. The date is in the format: "effective_date":"\/Date(978411600000)\/"

According to this SO question: How do I set up Microsoft JSON date? , it would be better if the date were returned in ISO 8601 format, so JavaScript would be able to interpret it as a date.

I am currently using the following javascript: new Date(d.effective_date) , and I am getting an Invalid Date message. In line with the related SO question, I should be able to do this if I can get the web service to transmit the date in ISO format and not in \/Date(978411600000)\/ format.

My question is: how can I get webservice to return a date in ISO 8601 format?

Note: I know that I can use this (for the answer from a related question): var date = new Date(parseInt(d.effective_date.substr(6))); however, the comment states that Incoming date values should be formatted in ISO-8601 , so I'm wondering how to get the incoming date from the web service to be in this ISO format.

+5
source share
1 answer

You can use:

 var date = new Date(d.effective_date); date.toISOString(); // ISO-8601 formatted string 

JSFiddle: http://jsfiddle.net/nanndoj/gjtkvrsy/

0
source

Source: https://habr.com/ru/post/1210220/


All Articles