-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTimeConversion.cs
More file actions
59 lines (49 loc) · 1.26 KB
/
Copy pathTimeConversion.cs
File metadata and controls
59 lines (49 loc) · 1.26 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace TimeConversion {
public class TimeConversion {
public static void Main(string[] args) {
string[] originalTime = (System.Console.ReadLine()).Split(':');
if (is_pm(originalTime[originalTime.Length - 1]))
System.Console.WriteLine(convert_pm(originalTime));
else
System.Console.WriteLine(convert_am(originalTime));
System.Console.ReadKey();
}
public static bool is_pm(string time) {
if (time.Contains("PM"))
return true;
else
return false;
}
public static string convert_am(string[] time) {
string result = "";
string[] AM = time[time.Length - 1].Split('A');
time[time.Length - 1] = AM[0];
if (time[0] == "12")
time[0] = "00";
for (int i = 0; i < time.Length; i++) {
result += time[i];
if (i == 2)
break;
result += ":";
}
return result;
}
public static string convert_pm(string[] time) {
string result = "";
string[] PM = time[time.Length - 1].Split('P');
time[time.Length - 1] = PM[0];
int newTime = System.Int32.Parse(time[0]) + 12;
if (newTime == 24)
time[0] = "12";
else
time[0] = newTime.ToString();
for (int i = 0; i < time.Length; i++) {
result += time[i];
if (i == 2)
break;
result += ":";
}
return result;
}
}
}