Jump to content

Help with timezone display?


Recommended Posts

Hi guys! Can someone help me display the time on a specific time zone represented by a label?

$Form2 = GUICreate("Form2", 405, 294, 142, 192)
$Label1 = GUICtrlCreateLabel("Label1", 48, 48, 36, 17)  ;EST
$Label2 = GUICtrlCreateLabel("Label2", 48, 88, 36, 17) ;PST etc etc.
GUISetState(@SW_SHOW)



Sorry I'm still a beginner on this language but I'm glad the people in this community are helpful!
I know I have to use the _Date_Time_GetTimeZoneInformation function but I can't seem to understand it clearly. I want to display the PST, MST, CST, and EST time in a Label or an Inputbox if possible. and can I do it in a 12 Hr format? with the AM/PM label?

any help would be appreciated. or any small examples. Cheers!

Link to comment
Share on other sites

Well, that was educational... for me anyway :)

You need to do some work:

Check the summer time / winter time transition date.

Check the whole thing is sane for winter - summer transitions for your local machines.

Check I have correctly defined all the timezone stuff, I'm not in North America, so I just put down some values from memory to test it ran.

#include <GUIConstantsEx.au3>
#include <Date.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $Form2 = GUICreate("Form2", 405, 294, 142, 192)
Global $Label1 = GUICtrlCreateLabel("Label1", 48, 48, 172, 17)  ;EST
Global $Label2 = GUICtrlCreateLabel("Label2", 48, 88, 172, 17) ;PST etc etc.
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIExit")
GUISetState(@SW_SHOW)

Global Const $Tag_Struct = "struct; long Bias;wchar StdName[32];word StdDate[8];long StdBias;wchar DayName[32];word DayDate[8];long DayBias; endstruct"
Global $EST_info = DllStructCreate ($Tag_Struct)
DllStructSetData ($EST_info, "Bias", 300)
DllStructSetData ($EST_info, "StdName", "Eastern Standard Time (Winter)")
DllStructSetData ($EST_info, "StdDate", _Date_Time_EncodeSystemTime (10, 5, 0, 3, 0, 0))
DllStructSetData ($EST_info, "DayName", "Eastern Standard Time (Summer)")
DllStructSetData ($EST_info, "DayDate", _Date_Time_EncodeSystemTime (3, 5, 0, 2, 0, 0))
DllStructSetData ($EST_info, "DayBias", 300)

Global $PST_info = DllStructCreate ($Tag_Struct)
DllStructSetData ($PST_info, "Bias", 480)
DllStructSetData ($PST_info, "StdName", "Pacific Standard Time (Winter)")
DllStructSetData ($PST_info, "StdDate", _Date_Time_EncodeSystemTime (10, 5, 0, 3, 0, 0))
DllStructSetData ($PST_info, "DayName", "Pacific Standard Time (Summer)")
DllStructSetData ($PST_info, "DayDate", _Date_Time_EncodeSystemTime (3, 5, 0, 2, 0, 0))
DllStructSetData ($PST_info, "DayBias", 480)

Global $System, $EST, $PST

While 1
  $System = _Date_Time_GetSystemTime()
  $EST = _Date_Time_SystemTimeToTzSpecificLocalTime($System, DllStructGetPtr ($EST_info))
  $PST = _Date_Time_SystemTimeToTzSpecificLocalTime($System, DllStructGetPtr ($PST_info))
  GUICtrlSetData($Label1, _Date_Time_SystemTimeToDateTimeStr($EST))
  GUICtrlSetData($Label2, _Date_Time_SystemTimeToDateTimeStr($PST))
  Sleep(100)
WEnd

Func GUIExit()
  GUIDelete()
  Exit
EndFunc

Hopefully you can see how it is easy to add additional time zones.

Edit: Hmm, I thought about this some more and I think you will need to check that $System is being calculated correctly - I'm in GMT so this is not a problem for me and I can't easily test whether it converts a non-zero region time to UTC ok... just saying in case it does not work for you, this is probably why.

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

4 hours ago, SlackerAl said:

Well, that was educational... for me anyway :)

You need to do some work:

Check the summer time / winter time transition date.

Check the whole thing is sane for winter - summer transitions for your local machines.

Check I have correctly defined all the timezone stuff, I'm not in North America, so I just put down some values from memory to test it ran.

#include <GUIConstantsEx.au3>
#include <Date.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $Form2 = GUICreate("Form2", 405, 294, 142, 192)
Global $Label1 = GUICtrlCreateLabel("Label1", 48, 48, 172, 17)  ;EST
Global $Label2 = GUICtrlCreateLabel("Label2", 48, 88, 172, 17) ;PST etc etc.
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIExit")
GUISetState(@SW_SHOW)

Global Const $Tag_Struct = "struct; long Bias;wchar StdName[32];word StdDate[8];long StdBias;wchar DayName[32];word DayDate[8];long DayBias; endstruct"
Global $EST_info = DllStructCreate ($Tag_Struct)
DllStructSetData ($EST_info, "Bias", 300)
DllStructSetData ($EST_info, "StdName", "Eastern Standard Time (Winter)")
DllStructSetData ($EST_info, "StdDate", _Date_Time_EncodeSystemTime (10, 5, 0, 3, 0, 0))
DllStructSetData ($EST_info, "DayName", "Eastern Standard Time (Summer)")
DllStructSetData ($EST_info, "DayDate", _Date_Time_EncodeSystemTime (3, 5, 0, 2, 0, 0))
DllStructSetData ($EST_info, "DayBias", 300)

Global $PST_info = DllStructCreate ($Tag_Struct)
DllStructSetData ($PST_info, "Bias", 480)
DllStructSetData ($PST_info, "StdName", "Eastern Standard Time (Winter)")
DllStructSetData ($PST_info, "StdDate", _Date_Time_EncodeSystemTime (10, 5, 0, 3, 0, 0))
DllStructSetData ($PST_info, "DayName", "Eastern Standard Time (Summer)")
DllStructSetData ($PST_info, "DayDate", _Date_Time_EncodeSystemTime (3, 5, 0, 2, 0, 0))
DllStructSetData ($PST_info, "DayBias", 480)

Global $System, $EST, $PST

While 1
  $System = _Date_Time_GetSystemTime()
  $EST = _Date_Time_SystemTimeToTzSpecificLocalTime($System, DllStructGetPtr ($EST_info))
  $PST = _Date_Time_SystemTimeToTzSpecificLocalTime($System, DllStructGetPtr ($PST_info))
  GUICtrlSetData($Label1, _Date_Time_SystemTimeToDateTimeStr($EST))
  GUICtrlSetData($Label2, _Date_Time_SystemTimeToDateTimeStr($PST))
  Sleep(100)
WEnd

Func GUIExit()
  GUIDelete()
  Exit
EndFunc

Hopefully you can see how how it is easy to add additional time zones.

Edit: Hmm, I thought about this some more and I think you will need to check that $System is being calculated correctly - I'm in GMT so this is not a problem for me and I can't easily test whether it converts a non-zero region time to UTC ok... just saying in case it does not work for you, this is probably why.

Thank you so much!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...