Date Formats
The following are examples that show the output of formatting July 20, 1969 08:17:52.789 PM UTC. 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 more detail, visit the API documentation at Microsoft Learn.
Standard Formatting Methods
| Format String | Result |
|---|---|
| date.ToLongDateString() | Sunday, 20 July 1969 |
| date.ToLongTimeString() | 20:17:52 |
| date.ToShortDateString() | 07/20/1969 |
| date.ToShortTimeString() | 20:17 |
| date.ToString() | 07/20/1969 20:17:52 |
Predefined Formats
| Format String | Result |
|---|---|
| d | 07/20/1969 |
| D | Sunday, 20 July 1969 |
| f | Sunday, 20 July 1969 20:17 |
| F | Sunday, 20 July 1969 20:17:52 |
| g | 07/20/1969 20:17 |
| G | 07/20/1969 20:17:52 |
| m -or- M | July 20 |
| o -or- O | 1969-07-20T20:17:52.7890000Z |
| r -or- R | Sun, 20 Jul 1969 20:17:52 GMT |
| s | 1969-07-20T20:17:52 |
| t | 20:17 |
| T | 20:17:52 |
| u | 1969-07-20 20:17:52Z |
| U | Sunday, 20 July 1969 20:17:52 |
| y -or- Y | 1969 July |
Custom Format Strings
| Format String | Result |
|---|---|
| d -or- %d | 20 |
| dd | 20 |
| ddd | Sun |
| dddd | Sunday |
| M -or- %M | 7 |
| MM | 07 |
| MMM | Jul |
| MMMM | July |
| y -or- %y | 69 |
| yy | 69 |
| yyy | 1969 |
| yyyy | 1969 |
| yyyyy | 01969 |
| gg | A.D. |
| h -or- %h | 8 |
| hh | 08 |
| H -or- %H | 20 |
| HH | 20 |
| m -or- %m | 17 |
| mm | 17 |
| s -or- %s | 52 |
| ss | 52 |
| 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 | P |
| tt | PM |
| z -or- %z | +0 |
| zz | +00 |
| zzz | +00:00 |