Time Conversion

  • + 0 comments

    Here is my c++ code

    string timeConversion(string s) {
    string hour= s.substr(0,2);
    string ms= s.substr(2,6);
    string meridian= s.substr(8,2);
    int clock = stoi(hour);
    if(meridian=="AM")
    {
        if(clock==12)
        {
            hour="00";
        }
    }
    else if(meridian =="PM")
    {
        if(hour!="12")
        {
            clock+=12;
            hour  =to_string(clock);
        }
    }
    return hour+ms;
    }