Date Formatting

The following are examples that show the output of formatting October 3, 1977 3:24.46.789 AM EST. Note that there are many more things you can do as far as formatting dates in the framework. For example the samples below do not even broach the subject of culture specific formatting. For (significantly) more detail, visit the API documentation at MSDN.

Standard Formatting Methods
Format String Result
date.ToLongDateString() Monday, October 3, 1977
date.ToLongTimeString() 3:24:46 AM
date.ToShortDateString() 10/3/77
date.ToShortTimeString() 3:24 AM
date.ToString() 10/3/77 3:24:46 AM
Predefined Formats
Format String Result
d 10/3/77
D Monday, October 3, 1977
f Monday, October 3, 1977 3:24 AM
F Monday, October 3, 1977 3:24:46 AM
g 10/3/77 3:24 AM
G 10/3/77 3:24:46 AM
m -or- M October 3
o -or- O 1977-10-03T03:24:46.7890000-04:00
r -or- R Mon, 03 Oct 1977 03:24:46 GMT
s 1977-10-03T03:24:46
t 3:24 AM
T 3:24:46 AM
u 1977-10-03 03:24:46Z
U Monday, October 3, 1977 7:24:46 AM
y -or- Y October 1977
Custom Format Strings
Format String Result
d -or- %d 3
dd 03
ddd Mon
dddd Monday
M -or- %M 10
MM 10
MMM Oct
MMMM October
y -or- %y 77
yy 77
yyy 1977
yyyy 1977
yyyyy 01977
gg AD
h -or- %h 3
hh 03
H -or- %H 3
HH 03
m -or- %m 24
mm 24
s -or- %s 46
ss 46
f -or- %f 7
ff 78
fff 789
ffff 7890
fffff 78900
ffffff 789000
fffffff 7890000
F -or- %F 7
FF 78
FFF 789
FFFF 789
FFFFF 789
FFFFFF 789
FFFFFFF 789
t -or- %t A
tt AM
z -or- %z -4
zz -04
zzz -04:00