Page 1 of 1

Different return in GUI

Posted: Fri Apr 17, 2020 10:24 am
by mattys
Any idea why I get a different return when placing into a gui form?
I ultimately am wanting to display the time only, in Eastern Time. ex. 03:12:45 PM
This works in ISE, but in my form I get a different result? ex. 04/17/2020 15:12:45 Confused on why.
  1. $timerClock_Tick = {
  2.  
  3.    
  4.  
  5.     #Temporarily stop the timer
  6.  
  7.     $timerClock.Stop()
  8.  
  9.    
  10.  
  11.     #Get Time in ET New York Time#
  12.  
  13.     $estzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time")
  14.  
  15.     $mkttime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $estzone)
  16.  
  17.     $ETtime = Get-Date $mkttime -DisplayHint Time
  18.  
  19.    
  20.  
  21.     $LabelNYtime.Text= $ETtime
  22.  
  23.     #Resume the timer
  24.  
  25.     $timerClock.Start()
  26.  
  27. }
Any help is appreciated.

Thanks

Re: Different return in GUI

Posted: Fri Apr 17, 2020 12:49 pm
by jvierra
Don't over-code this. Just convert and assign.

Code: Select all

$LabelNYtime.Text =  [System.TimeZoneInfo]::ConvertTimeFromUtc([datetime]::Now.ToUniversalTime(),[System.TimeZoneInfo]::FindSystemTimeZoneById('US Eastern Standard Time'))

Code: Select all

$timerClock_Tick = {
    $timerClock.Stop()
    $LabelNYtime.Text = [System.TimeZoneInfo]::ConvertTimeFromUtc([datetime]::Now.ToUniversalTime(),[System.TimeZoneInfo]::FindSystemTimeZoneById('US Eastern Standard Time'))
    $timerClock.Start() 
}
Simplicity is the best way to avoid coding errors.