first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

DateTime.ToString() Patterns in PowerShell

This is the output:

MM/dd/yyyy ==> 10/01/2007

dddd, dd MMMM yyyy ==> Monday, 01 October 2007

MM/dd/yyyy HH:mm ==> 10/01/2007 14:35

MM/dd/yyyy hh:mm tt ==> 10/01/2007 02:35 PM

MM/dd/yyyy h:mm tt ==> 10/01/2007 2:35 PM

MM/dd/yyyy HH:mm:ss ==> 10/01/2007 14:35:48

MMMM dd ==> October 01

yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK ==> 2007-10-01T14:35:48.7031250-07:00

ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ==> Mon, 01 Oct 2007 14:35:48 GMT

yyyy'-'MM'-'dd'T'HH':'mm':'ss ==> 2007-10-01T14:35:48

HH:mm ==> 14:35

hh:mm tt ==> 02:35 PM

HH:mm:ss ==> 14:35:48

yyyy'-'MM'-'dd HH':'mm':'ss'Z' ==> 2007-10-01 14:35:48Z

dddd, dd MMMM yyyy HH:mm:ss ==> Monday, 01 October 2007 14:35:48

yyyy MMMM ==> 2007 October

d ==> 10/1/2007

D ==> Monday, October 01, 2007

f ==> Monday, October 01, 2007 2:35 PM

F ==> Monday, October 01, 2007 2:35:48 PM

g ==> 10/1/2007 2:35 PM

G ==> 10/1/2007 2:35:48 PM

m ==> October 01

r ==> Mon, 01 Oct 2007 14:35:48 GMT

s ==> 2007-10-01T14:35:48

u ==> 2007-10-01 14:35:48Z

U ==> Monday, October 01, 2007 9:35:48 PM

y ==> October, 2007

This is the PowerShell script that produced the output:

$d = [System.DateTime]::Now

$s = "MM/dd/yyyy", "dddd, dd MMMM yyyy", "MM/dd/yyyy HH:mm", "MM/dd/yyyy hh:mm tt", "MM/dd/yyyy h:mm tt", "MM/dd/yyyy HH:mm:ss", "MMMM dd", "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK", "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'", "yyyy'-'MM'-'dd'T'HH':'mm':'ss", "HH:mm", "hh:mm tt", "HH:mm:ss", "yyyy'-'MM'-'dd HH':'mm':'ss'Z'", "dddd, dd MMMM yyyy HH:mm:ss", "yyyy MMMM", "d", "D", "f", "F", "g", "G", "m", "r", "s", "u", "U", "y"

foreach( $format in $s ) { $output = [System.String]::Format("{0} ==> {1}{2}", $format,$d.ToString( $format ), [System.Environment]::NewLine ) Write-Host $output }

mod date: 2007-10-01T21:39:54.000Z