-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1-ad-hoc.cs
More file actions
44 lines (39 loc) · 1009 Bytes
/
1-ad-hoc.cs
File metadata and controls
44 lines (39 loc) · 1009 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
35
36
37
38
39
40
41
42
43
44
using System;
// Ad-hoc polymorphism: function overloading
static class DateFormatter
{
public static string FormatDate(DateTime value, string locales = "en-US")
{
return value.ToString("yyyy-MM-dd");
}
public static string FormatDate(long timestamp, string locales = "en-US")
{
var date = new DateTime(1970, 1, 1).AddSeconds(timestamp);
return date.ToString("yyyy-MM-dd");
}
public static string FormatDate(string value, string locales = "en-US")
{
var date = DateTime.Parse(value);
return date.ToString("yyyy-MM-dd");
}
}
class Program
{
static void Main()
{
Console.WriteLine(
"formatDate(DateTime): {0}",
DateFormatter.FormatDate(new DateTime(2025, 10, 31))
);
Console.WriteLine(
"formatDate(timestamp): {0}",
DateFormatter.FormatDate(
DateTimeOffset.Now.ToUnixTimeSeconds()
)
);
Console.WriteLine(
"formatDate(string): {0}",
DateFormatter.FormatDate("2025-10-31T12:30:00Z")
);
}
}