Time Conversion

  • + 0 comments

    function timeConversion(time12h) { const period = time12h.slice(-2); // "AM" or "PM" let [hour, minute, second] = time12h.slice(0, -2).split(':');

    if (period === 'PM' && hour !== '12') {
        hour = String(parseInt(hour, 10) + 12);
    } else if (period === 'AM' && hour === '12') {
        hour = '00';
    }
    
    return ``${hour.padStart(2, '0')}:$`{minute}:${second}`;
    

    }