Skip to content
Related Articles

Related Articles

Moment.js Parsing Date

View Discussion
Improve Article
Save Article
  • Last Updated : 18 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 an object to parse dates represented as Date object.

The moment() function is used to create a moment using a Date object.

Syntax:

moment( Date )

Parameters: It takes a Date object representing the specified date.

Return Value: It returns a Moment object.

Example 1:

Javascript




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

Output:

 

Example 2:

Javascript




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

Output:

 

Reference: https://momentjs.com/docs/#/parsing/date/

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!