Skip to content
Advertisement

How to display time in required format?

I need to display time in HH:MM AM/PM format. date format :

JavaScript

function to convert date in HH:MM format:

JavaScript

Advertisement

Answer

You can format the time using Date.prototype.toLocaleTimeString(). The documentation includes examples of options you can pass-in.

If hour12 is false, the time will be rendered in 24-hour time and the meridiem will not be included.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement