How to get time format to hh:mm using moment.js?

Member

by lottie , in category: Javascript , 15 days ago

How to get time format to hh:mm using moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 14 days ago

@lottie 

To get the time format to hh:mm using Moment.js, you can use the following code snippet:

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

const currentTime = moment().format('HH:mm');

console.log(currentTime);


This code snippet uses Moment.js to get the current time in the format 'HH:mm'. The 'HH' token represents the hour in 24-hour format and the 'mm' token represents the minutes. You can customize the format by adjusting the format string in the format() function.