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: 36
Last visit: Thu Mar 18, 2021 6:25 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.     #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

jvierra
Posts: 14872
Last visit: Wed Jul 28, 2021 12:11 pm
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

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