Convert the 24 hours format time to 12 hours formatted time.

You can get the time byΒ ,
var dt = new Date();
var hours = dt.getHours(); // gives the value in 24 hours format
var minutes = dt.getMinutes() ;
var finalTime = "Time - " + hours + ":" + minutes;
finalTime // final time Time - 22:10
Now in-order to convert it to 12 hours format you can take % 12 on the current time.
If the time is 13 then 13%12 β 1
time = 23 then 23%12 β11
time = 24, then 24%12 β 0Β , if the time is 0, then change the time as 12.
var dt = new Date();
var hours = dt.getHours() ; // gives the value in 24 hours format
var AmOrPm = hours >= 12 ? 'pm' : 'am';
hours = (hours % 12) || 12;
var minutes = dt.getMinutes() ;
var finalTime = "Time - " + hours + ":" + minutes + " " + AmOrPm;
finalTime // final time Time - 22:10
If you find this helpful surprise π me here.
Share if you feel happy.
Follow Javascript Jeepπ if you feel worthy.