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.     #Temporarily stop the timer
  4.     $timerClock.Stop()
  5.    
  6.     #Get Time in ET New York Time#
  7.     $estzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time")
  8.     $mkttime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $estzone)
  9.     $ETtime = Get-Date $mkttime -DisplayHint Time
  10.    
  11.     $LabelNYtime.Text= $ETtime
  12.     #Resume the timer
  13.     $timerClock.Start()
  14. }
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.