Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Convert-UTCtoDateTime{
- #Parameter Binding
- [CmdletBinding()]
- param(
- [Parameter(Mandatory=$True,Position=1)][string]$UTC,
- [Parameter(Mandatory=$false)][switch]$ToLocal
- )
- #Breakout the various portions of the time with substring
- #This is very inelegant, and UTC
- $yyyy = $UTC.substring(0,4)
- $M = $UTC.substring(4,2)
- $dd = $UTC.substring(6,2)
- $hh = $UTC.substring(8,2)
- $mm = $UTC.substring(10,2)
- $ss = $UTC.substring(12,2)
- $fff = $UTC.substring(15,3)
- $zzz = $UTC.substring(22,3)
- #If local, add the UTC offset returned by get-date
- if($ToLocal){
- (get-date -Year $yyyy -Month $M -Day $dd -Hour $hh -Minute $mm -Second $ss -Millisecond $fff) + (get-date -format "zzz")
- }
- #else just return the UTC time
- else{
- get-date -Year $yyyy -Month $M -Day $dd -Hour $hh -Minute $mm -Second $ss -Millisecond $fff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement