How to get right format in moment.js?

Member

by dedrick , in category: Javascript , 7 months ago

How to get right format in moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 5 months ago

@dedrick 

To get the right format in Moment.js, you can use the format() function. Here's an example:

1
2
3
4
5
6
const moment = require('moment');

const currentDate = moment();
const formattedDate = currentDate.format('YYYY-MM-DD HH:mm:ss');

console.log(formattedDate);


In this example, currentDate.format('YYYY-MM-DD HH:mm:ss') will return the formatted date in the desired format, which is YYYY-MM-DD HH:mm:ss. You can change the format according to your needs.


Note that you would need to have Moment.js library installed and included in your code before you can use it.