Thursday, March 02, 2006

Formatting Date Output in C# with System.DateTime

Here is great page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp

The quick and dirty is, pass the following strings to DateTime.ToString( ); to get these outputs

d 1/3/2002
M/d/yyyy (ShortDatePattern)

D Thursday, January 03, 2002
dddd, MMMM dd, yyyy (LongDatePattern)

f Thursday, January 03, 2002 12:00 AM

F Thursday, January 03, 2002 12:00:00 AM
dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

g 1/3/2002 12:00 AM

G 1/3/2002 12:00:00 AM

m January 03
MMMM dd (MonthDayPattern)

M January 03
MMMM dd (MonthDayPattern)

r Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

R Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

s 2002-01-03T00:00:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

t 12:00 AM
h:mm tt (ShortTimePattern)

T 12:00:00 AM
h:mm:ss tt (LongTimePattern)

u 2002-01-03 00:00:00Z
yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

U Thursday, January 03, 2002 8:00:00 AM

y January, 2002
MMMM, yyyy (YearMonthPattern)

Y January, 2002
MMMM, yyyy (YearMonthPattern)

No comments: