We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Time Conversion
  2. Discussions

Time Conversion

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • ofurhieraphael20
    9 months ago+ 0 comments

    c++ code

    string timeConversion(string s) {
     int pos = s.find(":");
     int t = stoi(s.substr(0,pos));
     string r = s.substr(8,2);
    if(t == 12 && r =="AM")return "00"+s.substr(pos,6);
    else if(t <12 && r=="PM")return to_string((t+12))+s.substr(pos,6);
    else return s.substr(0,8);
    }
    
    19|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature