Open In App

Moment.js Parsing Now

Last Updated : 24 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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/


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads