Difference between revisions of "6236 Programmering I Agenda/Date time"
From Teknologisk videncenter
Line 23: | Line 23: | ||
</pre> | </pre> | ||
+ | |||
+ | <source lang=Csharp> | ||
+ | String s="31/12-2015"; | ||
+ | DateTime d = Convert.ToDateTime(s); | ||
+ | System.Console.WriteLine(d.ToString("dd:MM:yyyy")); | ||
+ | </source> |
Revision as of 11:03, 20 November 2015
Hvis der skal gemmes en dato i C# kan det gøres i datatypen DateTime.
//Opret en DateTime med datoen 31/12-2015 Kl 22:25:05
DateTime d = new DateTime(2015, 12, 31, 22, 25, 05);
//Udskriv DateTime i formatet
System.Console.WriteLine(d.ToString("dd.MM.yyyy HH:mm:ss"));
31.12.2015 22:25:05
Opgave
Ret i programmet så output formatet bliver
31. Dec 2015 kl 10:25:05 PM
String s="31/12-2015";
DateTime d = Convert.ToDateTime(s);
System.Console.WriteLine(d.ToString("dd:MM:yyyy"));