C# date and time

Updated: 07 July 2023

Custom date and time format strings

string ds = "Sat 23 Dec 2023";
DateTime dt = DateTime.ParseExact(ds, "ddd dd MMM yyyy", CultureInfo.InvariantCulture);
Console.Write(dt.ToString());

Specify year, month, day, hour, min, seconds, UTC timezone

DateTime dt = new DateTime(2015, 12, 31, 5, 10, 20, DateTimeKind.Utc);

Leave a comment