How to easy format date/time
One of the easiest ways to format date and time is the command
get-date -format <string>
<string> represents the format specifier. For a list of available format specifiers, see the System.Globalization.DateTimeFormatInfo Class topic in MSDN or look at these examples:
PS> get-date -format d
5/21/2007
PS> get-date -format D
Monday, May 21, 2007
PS> get-date -format f
Monday, May 21, 2007 9:24 PM
PS> get-date -format F
Monday, May 21, 2007 9:24:41 PM
PS> get-date -format g
5/21/2007 9:24 PM
PS> get-date -format G
5/21/2007 9:24:50 PM
PS> get-date -format m
May 21
PS> get-date -format M
May 21
PS> get-date -format o
2007-05-21T21:25:03.4218750+02:00
PS> get-date -format r
Mon, 21 May 2007 21:25:09 GMT
PS> get-date -format R
Mon, 21 May 2007 21:25:12 GMT
PS> get-date -format s
2007-05-21T21:25:17
PS> get-date -format t
9:25 PM
PS> get-date -format T
9:25:23 PM
PS> get-date -format u
2007-05-21 21:25:28Z
PS> get-date -format U
Monday, May 21, 2007 7:25:34 PM
PS> get-date -format y
May, 2007
PS> get-date -format Y
May, 2007
This blog entry has been inspired by Per Ostergaard and Jeffrey Snover.
No comments:
Post a Comment