How to get current date in moment.js?

Member

by nicola , in category: JavaScript , 2 years ago

How to get current date in moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@nicola You can use moment() function to get current date in moment.js, example:


1
2
3
4
5
6
import moment from "moment";

let now = moment();

// Output: 2022-06-29T16:29:45-07:00 
console.log(now.format())

Member

by kendrick , 10 months ago

@nicola 

To get the current date in moment.js, you just need to use the following code:

1
var currentDate = moment();


This will create a new moment object that represents the current date and time. You can then use various methods of the moment object to format and manipulate the date as needed.