How to get right format in moment.js?

Member

by dedrick , in category: Javascript , a year ago

How to get right format in moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , a year 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.

Related Threads:

How to get 'a.m.' format in moment.js?
How to get time format to hh:mm using moment.js?
How to add and format date in moment.js?
How to modify date format using moment.js?
How to add days using moment.js with format of mm/dd/yyyy?
How to get current time in hh:mm:ss format using moment in react.js?