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.
Solution in C# -
class Solution {
static string timeConversion(string s) {
s = s.Substring(0,8)+" "+s.Substring(8);
DateTime d = DateTime.Parse(s);
return d.ToString("HH:mm:ss");
}
static void Main(string[] args) {
TextWriter tw = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
string s = Console.ReadLine();
string result = timeConversion(s);
tw.WriteLine(result);
tw.Flush();
tw.Close();
}
}
Post a Comment