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, 03 October 1977 |
date.ToLongTimeString() | 03:24:46 |
date.ToShortDateString() | 10/03/1977 |
date.ToShortTimeString() | 03:24 |
date.ToString() | 10/03/1977 03:24:46 |
Predefined Formats
Format String | Result |
---|---|
d | 10/03/1977 |
D | Monday, 03 October 1977 |
f | Monday, 03 October 1977 03:24 |
F | Monday, 03 October 1977 03:24:46 |
g | 10/03/1977 03:24 |
G | 10/03/1977 03:24:46 |
m -or- M | October 03 |
o -or- O | 1977-10-03T03:24:46.7890000+00:00 |
r -or- R | Mon, 03 Oct 1977 03:24:46 GMT |
s | 1977-10-03T03:24:46 |
t | 03:24 |
T | 03:24:46 |
u | 1977-10-03 03:24:46Z |
U | Monday, 03 October 1977 03:24:46 |
y -or- Y | 1977 October |
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 | A.D. |
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 | +0 |
zz | +00 |
zzz | +00:00 |