You are viewing a single comment's thread. Return to all comments →
Here is a C++ solution:
string timeConversion(string s) { int hh = stoi(s.substr(0, 2)); string mm = s.substr(3, 2); string ss = s.substr(6, 2); string time,hour; if (s.substr(8, 1) == "P") { hour = (hh!=12 ? to_string(hh+=12) : to_string(hh)); time = hour + ":" + mm + ":" + ss; } else { if(hh==12) hour = "00"; else hour = (hh<10 ? "0":"")+ to_string(hh); time = hour + ":" + mm + ":" + ss; } return time; }
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Here is a C++ solution: