The method I shared yesterday is a little different than what you were doing, because I pulled out the individual pieces so that you could do something with them (like pass them in as parameters to Get-Date). I was in a hurry when I shared that though. Now that I had more time, I was able to find what I wanted to share yesterday. I just couldn’t find it in a hurry and it’s not something I use often enough that I could recall which method it was.
<pre class=”d4pbbc-pre”>[DateTime]::ParseExact($date, ‘MMM dd HH:mm:ss zzz’, $null)This will give you exactly what you are looking for. If the date format changes, refer to this blog post for the values you can use to specify what the format is: http://winpowershell.blogspot.ca/2006/09/systemdatetime-parseexact.html Note that this will return an error if you do not provide a string that matches the format identified. For example, if you used hh instead of HH, then you would get an error because the hour is in 24-hour format, not 12-hour format. Kirk out.
How should I be running this now?
$date = $month,$day,$hour,$minute,$second,$timezone = ‘Jul 16 16:08:30 +00:00′ -split ‘[: ]‘,6
[DateTime]::ParseExact($date, ‘MMM dd HH:mm:ss zzz’, $null)
Does not seem right. I haven’t had my coffee yet, and my brain is not working at 100%
Ok, I got it. This works nicely:
$date = ‘Jul 16 16:08:30 +00:00′
[DateTime]::ParseExact($date, ‘MMM dd HH:mm:ss zzz’, $null)