-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeConversion.cs
More file actions
34 lines (26 loc) · 711 Bytes
/
TimeConversion.cs
File metadata and controls
34 lines (26 loc) · 711 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
// @link Problem definition [[docs/hackerrank/warmup/time_conversion.md]]
namespace algorithm_exercises_csharp.hackerrank.warmup;
using System.Diagnostics.CodeAnalysis;
public class TimeConversion
{
[ExcludeFromCodeCoverage]
protected TimeConversion() { }
public static string timeConversion(string _s)
{
string meridian = _s[^2..];
meridian = meridian.ToLower();
string time_str = _s[0..(_s.Length - 2)];
List<string> time = [.. time_str.Split(":")];
int hour = Int32.Parse(time[0]);
if (hour >= 12)
{
hour = 0;
}
if (meridian == "pm")
{
hour += 12;
}
time[0] = String.Format("{0:00}", hour);
return String.Join(":", time);
}
}