format a date in to the format october 13, 2014 11:13:00.000 am gmt-07:00 in csharp

You can format a datetime object to the desired format using the ToString method and a custom format string. Here's an example in C#:

main.cs
DateTime date = new DateTime(2014, 10, 13, 11, 13, 0);
string formattedDate = date.ToString("MMMM dd, yyyy h:mm:ss.fff tt \"GMT\"zzz");

Console.WriteLine(formattedDate); // output: October 13, 2014 11:13:00.000 AM GMT-07:00
225 chars
5 lines

In the format string, MMMM represents the full month name (October), dd represents the zero-padded day of the month (13), yyyy represents the four-digit year (2014), h represents the 12-hour clock hour (11), mm represents the zero-padded minute (13), ss represents the zero-padded second (00), fff represents the milliseconds (000), tt represents the AM/PM designator (AM), "GMT" represents a literal string GMT, and zzz represents the timezone offset (-07:00).

gistlibby LogSnag