Question: Time Conversion C++: Given a time in -hour AM/PM format, convert it to military (24-hour) time. Note: Midnight is 12:00:00AM on a 12-hour clock, and

Time Conversion C++: Given a time in -hour AM/PM format, convert it to military (24-hour) time.

Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.

Input Format

A single string containing a time in -hour clock format (i.e.: or ), where and .

Output Format

Convert and print the given time in -hour format, where .

Sample Input

 07:05:45PM 

Sample Output

 19:05:45

I am stuck with this program can anyone please help in converting the 12 hour format to 24 hour format?

 #include <bits/stdc++.h> using namespace std; string timeConversion(string s) { // Complete this function string d,c; d=s.substr(8,2); if(d=="PM"){

then we add 12 hours h = h +12

}

Please complete the source code for the Time Conversion function and include comments explaining why your approach works. I know we are given a string called s and on this string we are also given the time information in the format hh:mm:ssPM. If the last two elements are A and M then we don't add anything to the hh and it stays the same, i.e. if we have 5 AM then the military format should also be 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!