Can anyone please help me get the HH:MM am/pm format instead of HH:MM:SS am/pm.
My javascript code is :
You can do this:
function prettyDate2(time){
var date = new Date(parseInt(time));
var localeSpecificTime = date.toLocaleTimeString();
return localeSpecificTime.replace(/:\d+ /, ' ');
}
The regex is stripping the seconds from that string.
A more general version from @CJLopez's answer:
function prettyDate2(time) {
var date = new Date(parseInt(time));
return date.toLocaleTimeString(navigator.language, {
hour: '2-digit',
minute:'2-digit'
});
}