Format date in C#

You can call the formatting methods on the DateTime class

DateTime time = DateTime.ParseExact("Mon, 28 Dec 2009 04:34:17", "ddd, dd MMM yyyy hh:mm:ss", CultureInfo.InvariantCulture);
string output = time.ToString("dd MMM yyyy", CultureInfo.InvariantCulture);

Here is a list of options for the format strings.

Leave a Comment