Time Conversion

  • + 0 comments

    Typescript:

    let hours = s.split(':')[0].toString();
    let minutes = s.split(':')[1].toString();
    let seconds = (s.split(':')[2].slice(0, 2)).toString();
    let timeType = s.split(':')[2].slice(-2);
    
    if (timeType == 'AM' && hours == '12') {
       hours = '00';
    } else if (timeType == 'PM' && Number(hours) < 12) {
       hours = (Number(hours) + 12).toString();
    }
    
    return `${hours}:${minutes}:${seconds}`;