# Parse.DateTime.ps1
# Sample using PowerShell
# thomas lee - tfl@psp.co.uk
# define date strings
$ds1 = "2008-05-01T07:34:42-5:00"
$ds2 = "2008-05-01 7:34:42Z"
$ds3 = "Thu, 01 May 2008 07:34:42 GMT"
# parse them
$cd1 = [system.datetime]::parse($ds1)
$cd2 = [system.datetime]::parse($ds2)
$cd3 = [system.datetime]::parse($ds3)
# Determine time type
$cd1type = $cd1.kind.tostring()
$cd1type = $cd2.kind.tostring()
$cd1type = $cd3.kind.tostring()
# output them
"Converted {0} to {1} time {2}" -f $ds1,$cd1type,$cd1
"Converted {0} to {1} time {2}" -f $ds2,$cd1type,$cd2
"Converted {0} to {1} time {2}" -f $ds3,$cd1type,$cd3
This script produces the following output:
Converted 2008-05-01T07:34:42-5:00 to Local time 5/1/2008 1:34:42 PM
Converted 2008-05-01 7:34:42Z to Local time 5/1/2008 8:34:42 AM
Converted Thu, 01 May 2008 07:34:42 GMT to Local time 5/1/2008 8:34:42 AM