Skip to content
Related Articles

Related Articles

Moment.js Parse ASP.NET JSON Date

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Jun, 2022
View Discussion
Improve Article
Save Article

Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed with a string to parse dates in ASP.NET JSON format.

The moment() function is used to create a moment using a string representing a date in ASP.NET JSON format.

Syntax:

moment( String )

Parameters: It takes a string that represents the date in ASP.NET JSON format.

Returns: A Moment object.

Example 1:

Javascript




import moment from 'moment';
  
let day = "/Date(1158639712897)/"
let date = moment(day);
console.log(date.format("DD/MM/YYYY-H:mm:ss"));

Output:

 

Example 2:

Javascript




import moment from 'moment';
  
let day = "/Date(1558639712897)/"
let date = moment(day);
console.log(date.format("dddd, Do MMM YYYY, h:mm:ss A"));

Output:

 

Reference: https://momentjs.com/docs/#/parsing/asp-net-json-date/

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!