Format TimeUnit
This Format TimeUnit
Function is used for
formatting the time with AM or PM
TimeUnit
timeUnit.ts
export function formatTimeUnit(time: string): string {
let hour = parseInt(time.split(':')[0]) % 12
hour = hour ? hour : 12
return `${hour}:${time.split(':')[1]} ${parseInt(time.split(':')[0]) >= 12 ? 'PM' : 'AM'}`
}
Usage
card.tsx
const time = formatTimeUnit('12:20')
Last updated on April 19, 2023