Convert string w/timezone to datetime type

by davidski at 2012-10-30 04:45:51

I’m struggling with what I suspect is a simple datetime conversion. I have datestamps with the format: Oct 29, 2012 3:59:48 PM PDT. The PDT timezone is throwing me off. It sounds like timezone abbreviations of this sort are not supported under .NET. Is that correct? What’s the simplest way of getting this converted over to a proper datetime object?

Current failed approach is:
$testdate = "Oct 29, 2012 3:59:48 PM PDT"
$timeformat = "MMM d, yyyy h:m:s tt zzz"
[datetime]::ParseExact( $testdate, $timeinfo, $null)

Many thanks for the help.
by DonJ at 2012-10-30 07:44:11
To my knowledge, they aren’t supported. That means there’s not going to be a simple way, unfortunately. This is something you might consider taking over to StackOverflow - I imagine some dev somewhere has had to solve this.
by davidski at 2012-10-30 09:23:00
Thanks, Don. Based on this posting on StackOverflow I implemented the hack below. It’s not robust, but it works for my limited needs.

$testdate = "Oct 29, 2012 3:59:48 PM PDT" -replace "\s\w+$" ""
$timeformat = "MMM d, yyyy h:m:s tt"
[datetime]::ParseExact( $testdate, $timeinfo, $null)