Time Conversion

  • + 0 comments

    This is my C++ solution for this problem. Hope! You wil find it useful.

    string timeConversion(string s) {
           string hr = s.substr(0,2);
           int h = stoi(hr);
           if (s[8]=='P') {
               if(h!=12)
                 h = h + 12;
            s.replace(0,2,to_string(h));     
           }
           if(s[8]=='A' && h==12 ){
                s.replace(0,2,"00");
           } 
           s.erase(8,2);
           return s;     
    }