format a date in to the format october 13, 2014 in csharp

In C#, you can format a date using the ToString() method and specifying the desired format. To format a date as "October 13, 2014", you can use the following code:

main.cs
DateTime date = new DateTime(2014, 10, 13);
string formattedDate = date.ToString("MMMM d, yyyy");
Console.WriteLine(formattedDate);
132 chars
4 lines

Output:

main.cs
October 13, 2014
17 chars
2 lines

In the ToString() method, "MMMM" represents the full month name, "d" represents the day of the month without a leading zero, and "yyyy" represents the four-digit year.

related categories

gistlibby LogSnag