-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeConversion.cs
More file actions
34 lines (29 loc) · 791 Bytes
/
TimeConversion.cs
File metadata and controls
34 lines (29 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace CodeChallenge
{
public class TimeConversion
{
public static string timeConversion(string s)
{
string amPm = s.Substring(s.Length - 2);
int hour = int.Parse(s.Substring(0, 2));
string timeWithoutAmPm = s.Substring(0, s.Length - 2);
if (amPm == "Am" || amPm == "am")
{
if (hour == 12)
{
hour = 0;
}
}
else
{
if (hour != 12)
{
hour += 12;
}
}
string hourString = hour.ToString("D2");
string result = hourString + timeWithoutAmPm.Substring(2);
return result;
}
}
}