Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47c3606

Browse files
feat(problem #82): add day-of-the-week
1 parent 48e3602 commit 47c3606

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎Easy/day-of-the-week.cs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class Solution
2+
{
3+
#region Without Using Built-In Functions
4+
public static byte DayOfWeekOrder(int day, int month, int year)
5+
{
6+
short a, y, m;
7+
a = (short)((14 - month) / 12);
8+
y = (short)(year - a);
9+
m = (short)(month + (12 * a) - 2);
10+
// Gregorian://0:sun, 1:Mon, 2:Tue...etc
11+
return (byte)((day + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7);
12+
}
13+
14+
public static string DayOfTheWeek(int day, int month, int year)
15+
{
16+
byte dayOfWeekOrder = DayOfWeekOrder(day, month, year);
17+
18+
string[] arrDayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
19+
return arrDayNames[dayOfWeekOrder];
20+
}
21+
#endregion
22+
23+
#region Using Built-In Functions
24+
public static string DayOfTheWeek2(int day, int month, int year)
25+
{
26+
DateTime date = new(year, month, day);
27+
return date.DayOfWeek.ToString();
28+
}
29+
#endregion
30+
31+
private static void Main()
32+
{
33+
Console.WriteLine(DayOfTheWeek2(31, 8, 2019));
34+
35+
Console.ReadKey();
36+
}
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /