Advertisement
Guest User

Convert-UTCtoDateTime

a guest
Oct 20th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Convert-UTCtoDateTime{
  2.  
  3.  
  4.     #Parameter Binding
  5.     [CmdletBinding()]
  6.     param(
  7.         [Parameter(Mandatory=$True,Position=1)][string]$UTC,
  8.         [Parameter(Mandatory=$false)][switch]$ToLocal
  9.         )
  10.  
  11.     #Breakout the various portions of the time with substring
  12.     #This is very inelegant, and UTC
  13.     $yyyy = $UTC.substring(0,4)
  14.     $M = $UTC.substring(4,2)
  15.     $dd = $UTC.substring(6,2)
  16.     $hh = $UTC.substring(8,2)
  17.     $mm = $UTC.substring(10,2)
  18.     $ss = $UTC.substring(12,2)
  19.     $fff = $UTC.substring(15,3)
  20.     $zzz = $UTC.substring(22,3)
  21.  
  22.     #If local, add the UTC offset returned by get-date
  23.     if($ToLocal){
  24.     (get-date -Year $yyyy -Month $M -Day $dd -Hour $hh -Minute $mm -Second $ss -Millisecond $fff) + (get-date -format "zzz")
  25.     }
  26.     #else just return the UTC time
  27.     else{
  28.     get-date -Year $yyyy -Month $M -Day $dd -Hour $hh -Minute $mm -Second $ss -Millisecond $fff
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement