Open In App

Moment.js Parsing Now

Last Updated : 24 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
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/


Next Article

Similar Reads