Using ISO-8601 format to display dates in JSON within a .NET WebService

While working with a .net asmx webservice, I encountered an issue with the date format being returned. The date field is in the form of:

"effective_date":"\/Date(978411600000)\/"

After researching on Stack Overflow here: How do I format a Microsoft JSON date?, it became clear that converting the date to ISO 8601 format would allow JavaScript to interpret it correctly.

Currently, when using new Date(d.effective_date) in JavaScript, I receive an error message stating Invalid Date. It was suggested in the SO question that formatting the date in ISO standard instead of \/Date(978411600000)\/ should resolve this issue.

Hence, my query is - how can I modify the webservice to return the date in ISO 8601 format?

Note: Although I am aware of using

var date = new Date(parseInt(d.effective_date.substr(6)));
as mentioned in one of the answers, the preferable approach according to a comment is for the incoming date values to be formatted in ISO-8601. Therefore, I'm seeking guidance on how to ensure the date from the web service comes in this ISO standard format.

Answer №1

Feel free to utilize the following code snippet:

let currentDate = new Date(d.effective_date);
currentDate.toISOString(); // Returns an ISO-8601 formatted string

Check out this JSFiddle example for more information: http://jsfiddle.net/xyz123abc/jhndkwoe/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React 18 doesn't trigger component re-rendering with redux

In my code, I have implemented a custom hook to handle global data fetching based on user authentication. Here is an example of the hook: const userState = useSelector(state => state.user.state) useEffect(() => { if(userState === "authentic ...

Go to a different webpage containing HTML and update the image source on that particular page

I am facing an issue with my html page which contains multiple links to another page. I need to dynamically change the image references on the landing page based on the link the user clicks. The challenge here is that the link is inside an iframe and trigg ...

Unable to write or upload error in a Node Express application

My GET and POST APIs are functioning properly, however, my app.put is not working as expected. https://i.sstatic.net/Oc0QT.png Upon sending a PUT request to localhost:3001/contacts/1 using Postman, I am unable to see the console.log output: https://i.ss ...

Tips for showcasing a restricted amount of data with Angular.js

I've been exploring different ways to limit the results using limitTo, but unfortunately, I'm encountering unexpected issues. Currently, the entire list is being displayed when I only want to show 8 key-value items in a 4/4 block format. You can ...

What is the process of linking a website to Android Studio for data sharing?

As a beginner in Android development, I have encountered a challenge where I need to automatically fill a text box (text view) in Android Studio with data (string) passed to a text box on a web page. How can I establish a connection between these two ele ...

Choosing the Following Date from the Datepicker using Selenium IDE

I need the selenium IDE test case to automatically select a date following the steps outlined below: Start by clicking on the departure date to open the datepicker Loop through the dates starting with the currently selected day until the next available d ...

The functionality of images and links is compromised when they are assigned as values to properties within a JSON object

My images and links are not working, even after declaring them globally. When I write the src directly into src, everything seems fine but the alert pops up with the same URL and img src. Can anyone help? var combo0; var combo1; var combo2; var combo3; ...

I have successfully integrated my custom external JavaScript code with React Router, and everything is working

Assistance Needed! I am working on a project that consists of 4 pages, one of which is the About page. I am using react-router to manage the paths and contents between these pages through their respective links. import React from 'react'; impo ...

Setting response query correctly in Solr using AJAX

Inspired by an example of using Solr's JSON output for AJAX, I have incorporated a drop-down menu into my project form and introduced faceting to the parameters. Parameters: function getstandardargs() { var params = [ 'wt=json' ...

Applying a transparent layer to all slider images, with the exception of the one that is

I am utilizing an IosSlider that is functioning properly, but I am looking to enhance it by adding opacity to all images except for the selected image. This adjustment will make the selected image stand out more and enable users to focus on one image at a ...

How can one effectively manage irregularly nested object/arrays within a Meteor framework?

Having difficulty finding a smart and effective method to manage nested arrays/objects with varying dimensions in nodeJS. These irregular arrays/objects can have 1, 2, 3, or more dimensions. For instance, consider these 2 different scenarios : Scenario 1 ...

The process of embedding variables within a JSON Array function in JavaScript

As a newcomer to JavaScript, I am facing an issue while trying to create a simple program. I am attempting to store the variables 'name', 'document', and 'code' inside the JSON array called 'records'. var records = ...

Using the JSONEncoder to serialize an array of custom objects along with extra data into JSON format

My custom encoder effortlessly serializes an array of Lightning custom objects. However, I now need to include additional data such as the number of Lightnings and another type in the serialization output. This is how the current serialization looks: [{&q ...

Generating elevation graph from a kml file with the combination of php and javascript

Currently, I am exploring the Google Elevation Service with the goal of creating an elevation profile similar to the one showcased in this example: Below is the JavaScript code snippet used: var elevator; var map; var chart; var infowindow = new google.m ...

Tips for enabling browser back and forward functionality in a one-page website design

Building on the previous discussion about optimizing a horizontal sliding layout (Most efficient way to do a horizontal sliding layout), I'm curious if it's feasible to enable the back and forward buttons in the browser when implementing a single ...

Ways to display multiple PHP pages in a single division

Within my project, I have a unique setup involving three distinct PHP pages. The first file contains two divisions - one for hyperlinked URLs and the other for displaying the output of the clicked URL. Here is an excerpt from the code snippet: <script& ...

How to obtain the full path of a file downloaded using a Chrome extension

Currently in the process of creating a chrome extension that has the functionality to download specific files from various webpages. For this purpose, I have designed a popup.html where users can input the desired name for the file to be downloaded. Additi ...

Failure to read the response will cause the HttpUrlConnection request to malfunction

I have been attempting to send a json request using HttpUrlConnection in Java. Despite following multiple examples, I am unable to successfully add data to the server as there is no response. Below is the code I am currently using: URL url = new URL(u ...

Generate a fresh FileReader instance using the downloaded file via XmlHTTPRequest

I am attempting to use an XmlHTTPRequest object (level 2) downloaded through a "GET" request in order to create a new FileReader object. My goal is to create the FileReader object within the onload function of the xhr. The file, which is a .gz file, downl ...

Error occurs when Anonymous authentication is disabled for a web application

Currently, my objective is to activate Windows authentication and deactivate anonymous authentication for an intranet application. I have successfully enabled Windows authentication and disabled anonymous in IIS7. Furthermore, I have configured my Web.Conf ...