This util function will convert the seconds (number) to the formatted Time Unit string.
/**
* Format Time Unit
* @param { number } minutes
* @returns { string } Formatted Time Unit
*/
export function formatTimeUnit(minutes) {
const hours = Math.floor(minutes / 60);
const remainingMinutes = minutes % 60;
const ampm = hours < 12 ? 'AM' : 'PM';
let hour12 = hours % 12;
if (hour12 === 0) {
hour12 = 12;
}
return `${hour12}:${String(remainingMinutes).padStart(2, '0')} ${ampm}`;
}
// Usage
const ftu = formatTimeUnit(3000)
console.log('ftu', ftu) // 2:00 PM