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

Member

by lottie , in category: Javascript , a year ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

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

Related Threads:

How to get current time in hh:mm:ss format using moment in react.js?
How to get right format in moment.js?
How to get 'a.m.' format in moment.js?
How to get time difference in moment.js?
How to modify date format using moment.js?
How to subtract time using moment.js?