Time Conversion

  • + 0 comments

    C++

    string timeConversion(string s) {
        int hour = stoi(s.substr(0,2));
    
        if (s[8] == 'P') {
            return (hour == 12) ? s.substr(0, 8) : to_string(hour + 12) + s.substr(2,6);
        } else {
            return (hour == 12) ? "00" + s.substr(2, 6) : s.substr(0, 8); 
        }
    }