Created
October 26, 2016 07:55
-
-
Save s0ren/1b921d5e45976a2508ac45b246ce926d to your computer and use it in GitHub Desktop.
Brug DateTime til at tælle søndage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
// Se også om DateTime | |
// https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx | |
// og om formatering | |
// https://msdn.microsoft.com/en-us/library/8tfzyc64(v=vs.110).aspx | |
namespace Søndage | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
DateTime dt = new DateTime(1965, 10, 2); | |
Console.WriteLine("Jeg er født på en " + dt.ToString("dddd")); | |
int søndageIMaj = 0; | |
for (int dag = 1; dag <= 31; dag++) | |
{ | |
DateTime mayDay = new DateTime(1867, 5, dag); | |
if (mayDay.ToString("dddd") == "søndag") | |
{ | |
Console.WriteLine(mayDay.ToString("dddd dd. MMMM yyyy")); | |
søndageIMaj++; | |
} | |
} | |
Console.WriteLine("Der er {0} søndage i maj 1867", søndageIMaj); | |
int sundaysInYear = 0; | |
DateTime dtY = new DateTime(1865, 1, 1); | |
while(dtY < new DateTime(1866, 1, 1)) | |
{ | |
if (dtY.ToString("dddd") == "søndag") | |
{ | |
sundaysInYear++; | |
} | |
dtY = dtY.AddDays(1); | |
} | |
Console.WriteLine("Der er {0} søndage i 1865", sundaysInYear); | |
sundaysInYear = 0; | |
dtY = new DateTime(1864, 1, 1); | |
while (dtY < new DateTime(1865, 1, 1)) | |
{ | |
if (dtY.ToString("dddd") == "søndag") | |
{ | |
sundaysInYear++; | |
} | |
dtY = dtY.AddDays(1); | |
} | |
Console.WriteLine("Der er {0} søndage i 1864", sundaysInYear); | |
sundaysInYear = 0; | |
dtY = new DateTime(1866, 1, 1); | |
while (dtY < new DateTime(1867, 1, 1)) | |
{ | |
if (dtY.ToString("dddd") == "søndag") | |
{ | |
sundaysInYear++; | |
} | |
dtY = dtY.AddDays(1); | |
} | |
Console.WriteLine("Der er {0} søndage i 1866", sundaysInYear); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment