Chapter 10. .NET DateTime Formatting
DateTime format strings convert a DateTime
object to one of several standard formats, as listed in Table 10-1.
Format specifier (Name) | Description | Example |
| The culture’s short date format. |
PS >"{0:d}" -f [DateTime] "01/23/4567" 1/23/4567 |
| The culture’s long date format. |
PS >"{0:D}" -f [DateTime] "01/23/4567" Friday, January 23, 4567 |
| Combines the long date and short time format patterns. |
PS >"{0:f}" -f [DateTime] "01/23/4567" Friday, January 23, 4567 12:00 AM |
| Combines the long date and long time format patterns. |
PS >"{0:F}" -f [DateTime] "01/23/4567" Friday, January 23, 4567 12:00:00 AM |
| Combines the short date and short time format patterns. |
PS >"{0:g}" -f [DateTime] "01/23/4567" 1/23/4567 12:00 AM |
| Combines the short date and long time format patterns. |
PS >"{0:G}" -f [DateTime] "01/23/4567" 1/23/4567 12:00:00 AM |
| The culture’s |
PS >"{0:M}" -f [DateTime] "01/23/4567" January 23 |
| The date formatted with a pattern that guarantees the string (when parsed) will result in the original |
PS >"{0:o}" -f [DateTime] "01/23/4567" 4567-01-23T00:00:00.0000000 |
| The standard RFC1123 format pattern. |
PS >"{0:R}" -f [DateTime] "01/23/4567" Fri, 23 Jan 4567 00:00:00 GMT |
| Sortable format pattern. Conforms ... |
Get Windows PowerShell Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.