Skip to content
Related Articles

Related Articles

Moment.js Parsing Now

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

Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed to get the current date and time.

The moment() function is used to create a moment with the current date and time.

Syntax:

moment() | moment(undefined) | moment([]) | moment({})

Parameters: It might take an empty array or object as a parameter.

Return Value: It returns a Moment object.

Example 1:

Javascript




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

Output:

 

Example 2:

Javascript




import moment from 'moment';
  
let date = moment([]);
date=date.subtract(1,'day')
console.log(date.format("DD/MM/YYYY-H:mm:ss"));

Output:

 

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!