Open In App

Moment.js Parsing Now

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:




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

Output:

 

Example 2:




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/

Article Tags :