Different return in GUI

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
mattys
Posts: 27
Joined: Mon Dec 30, 2019 10:58 am

Different return in GUI

Post 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

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Different return in GUI

Post 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.

Locked