MyEarth

Get time from other country

10 posts in this topic

#1 ·  Posted (edited)

Hi guys

I need to get time of different city, London, Jerusalem, Mosca and many others. My starting script:

#include <Date.au3>

Local $iUTC, $iHour, $iMinute, $iSecond
$iUTC = _Date_Time_GetSystemTime()
$iHour = DllStructGetData($iUTC, "Hour")
$iMinute = DllStructGetData($iUTC, "Minute")
$iSecond = DllStructGetData($iUTC, "Second")
ConsoleWrite("+UTC: " & $iHour & ":" & $iMinute & ":" & $iSecond & @CRLF)

My idea was start from UTC time and then add-remove hours. But what about the DST, Daylight Savings Time? How i can know if in a country is active or not? There is an API? Example with _Date_Time_GetTimeZoneInformation it will give the current time zone settings and not for other time zone. I don't have understand if is possible or not :lol:

On the help i have found SystemTimeToTzSpecificLocalTime but i don't have understand how to use for other time zone...

Thanks

Edited by MyEarth

Share this post


Link to post
Share on other sites



TIMEZONE                    SOLAR           LEGAL
Eastern Time Zone           EST (UTC-5)     EDT (UTC-4)
Central Time Zone           CST (UTC-6)     CDT (UTC-5)
Mountain Time Zone          MST (UTC-7)     MDT (UTC-6)
Pacific Time Zone           PST (UTC-8)     PDT (UTC-7)
Alaska Time Zone            AKST (UTC-9)    AKDT (UTC-8)
Hawaii-Aleutian Time Zone   HAST (UTC-10)   Hawaii do not use it

to do what you want before you have to understand some differences, so start from here and then calculates the differences

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have make some progress:

EDIT: Removed, see #10

I still need to know WHEN the DST (Daylight Savings Time) start and when end! Please an help with that, thanks

Check this page for more info:

TIME_ZONE_INFORMATION structure

Edited by MyEarth

Share this post


Link to post
Share on other sites

One of our regex gurus would be better able to assist with the parsing, but have you thought about just querying Google and then parsing your response? Something like:

https://www.google.com/?gws_rd=ssl#q=time+in+london

 

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Maybe this solution:

??

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

If i need to use internet i prefer to switch to something "professional" like an NTP server like windows does but the problem is still the same, the DST. I don't know how to extract this information from the TIME_ZONE_INFORMATION structure, are both there ( StandardDate and DaylightDate )

Edited by MyEarth

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This article is very intresting:

A Time Zone API supplement

Someone can traslate it? Please :D

It will resolve all my problem. Enumerate time zones and check the DST...

Sorry for the new post, a refresh problem of the browser.

Edited by MyEarth

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Let we check at one of the function?

/*
 * TZIEnum
 *
 * Get the list of TimeZones
 * Param:
 *      TIME_ZONE_INFORMATION pTZI  : The Time Zone Infomation array
 *      UINT cbTZI                  : Size of Array to fill
 * Return:
 *      UINT                        : Count of TZI structures enumerated
 *      The structures will be filled in in the TZI array
 */

extern "C"
UINT WINAPI TZIEnum(TIME_ZONE_INFORMATION *pTZI, UINT cbTZI)
{
    HKEY hKey;

     // Open the registry key where MS hides the Time Zones
    if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"), 0, KEY_READ, &hKey) == ERROR_SUCCESS )
    {
         // Get the number of time zones
        DWORD dwKeyCount;
        if( RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwKeyCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS )
        {
             // Empty?
            if( cbTZI == 0 )
            {
                RegCloseKey(hKey);
                return (UINT)dwKeyCount;
            }
             // Limit to what is available
            if( cbTZI > (UINT)dwKeyCount ) 
                cbTZI = (UINT)dwKeyCount;

             // Fill in the Standard Names
            for( UINT iIndex = 0; iIndex < cbTZI; ++iIndex )
            {
                DWORD dwLen = _countof(pTZI[0].StandardName);
                RegEnumKeyEx(hKey, iIndex, pTZI[iIndex].StandardName, &dwLen, NULL, NULL, NULL, NULL);
            }

             // Loop through the list using the standard names
            TZREG   tzr;
            for(UINT i = 0; i < cbTZI; ++i)
            {
                HKEY hKeyItem;
                 // Open the TZREG structure
                if( RegOpenKeyEx(hKey, pTZI[i].StandardName, 0, KEY_READ, &hKeyItem) == ERROR_SUCCESS )
                {
                     // Get the TZREG structure
                    DWORD dwLen = sizeof(pTZI[0].DaylightName);
                    DWORD dwType = REG_SZ;
                    RegQueryValueEx(hKeyItem, _T("Dlt"), NULL, &dwType, (LPBYTE)pTZI[i].DaylightName, &dwLen);
                    dwLen = sizeof(TZREG);
                    dwType = REG_BINARY;
                    RegQueryValueEx(hKeyItem, _T("TZI"), NULL, &dwType, (LPBYTE)&tzr, &dwLen);

                     // Copy the TZREG to the TZI
                    pTZI[i].Bias = tzr.Bias;
                    pTZI[i].DaylightBias = tzr.DaylightBias;
                    pTZI[i].DaylightDate = tzr.DaylightDate;
                    pTZI[i].StandardBias = tzr.StandardBias;
                    pTZI[i].StandardDate = tzr.StandardDate;

                     // Close the item
                    RegCloseKey(hKeyItem);
                }
            }
        }
         // Close the registry
        RegCloseKey(hKey);
    }
    else
        return 0;

     // Return the count
    return cbTZI;
}

 // Standard DoW calculation
static
int dayofweek(int y, int m, int d) /* 0 = Sunday / int y, m, d; / 1 <= m <= 12, y > 1752 or so */ 
{ 
    static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; 
    y -= m < 3; 
    if( m > 1 ) --m;
    return (y + y/4 - y/100 + y/400 + t[m%12] + d) % 7; 
}

As you can see most of the code is the same of what i have done at #3, looking at the key and get the info. Missing the last part, convert registry TZI values into TIME_ZONE_INFORMATION struct

// Copy the TZREG to the TZI
pTZI[i].Bias = tzr.Bias;
pTZI[i].DaylightBias = tzr.DaylightBias;
pTZI[i].DaylightDate = tzr.DaylightDate;
pTZI[i].StandardBias = tzr.StandardBias;
pTZI[i].StandardDate = tzr.StandardDate;

 

Edited by MyEarth

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

edit

Edited by MyEarth
wrong code

Share this post


Link to post
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

  • Similar Content

    • Realm
      By Realm
      After Several Minutes searching the forums for a simple solution to calculating for the Unix Time, as required for another project I am working on, I was astonished to not find one clean and universal solution. After looking over the helpfile, I noticed one simple solution given in the example with _DateDiff(). However it did not account for my current timezone or daylight savings time.
      Without further ado... This is my example of Calculating for a current Unix Time stamp or  seconds since Jan, 1st, 1970 00:00:00 GMT.
      This function will account for your timezone as well as for daylight savings time.
      Update: v0.3
      -Added Function to revert a Unix Time stamp into Date form.
      -Added parameter to original _GetUnixTime() allowing for a custom date since Jan 1st 1970 to be passed and converted to Unix Time.
      #include <Date.au3> #include <Array.au3> #include <Constants.au3> Local $iUnixTime1 = _GetUnixTime() MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds Since Jan, 1st, 1970 00:00:00 GMT" & @CRLF & $iUnixTime1) Local $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp in Local Time" & @CRLF & $sUnixDate1) $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1, False) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp with $iReturnLocal = False which returns UTC Time" & @CRLF & $sUnixDate1) Local $iUnixTime2 = _GetUnixTime('2013/01/01 00:00:00') MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds since 2013/01/01 00:00:00" & @CRLF & $iUnixTime2) ; Get timestamp for input datetime (or current datetime). Func _GetUnixTime($sDate = 0);Date Format: 2013/01/01 00:00:00 ~ Year/Mo/Da Hr:Mi:Se Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $utcTime = "" If Not $sDate Then $sDate = _NowCalc() If Int(StringLeft($sDate, 4)) < 1970 Then Return "" If $aSysTimeInfo[0] = 2 Then ; if daylight saving time is active $utcTime = _DateAdd('n', $aSysTimeInfo[1] + $aSysTimeInfo[7], $sDate) ; account for time zone and daylight saving time Else $utcTime = _DateAdd('n', $aSysTimeInfo[1], $sDate) ; account for time zone EndIf Return _DateDiff('s', "1970/01/01 00:00:00", $utcTime) EndFunc ;==>_GetUnixTime ;$blTrim: Year in short format and no seconds. Func _GetDate_fromUnixTime($iUnixTime, $iReturnLocal = True) Local $aRet = 0, $aDate = 0 Local $aMonthNumberAbbrev[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] Local $timeAdj = 0 If Not $iReturnLocal Then Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $timeAdj = $aSysTimeInfo[1] * 60 If $aSysTimeInfo[0] = 2 Then $timeAdj += $aSysTimeInfo[7] * 60 EndIf $aRet = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $iUnixTime + $timeAdj ) If @error Or Not $aRet[0] Then Return "" $aDate = StringSplit(StringTrimRight($aRet[0], 1), " ", 2) Return $aDate[4] & "/" & StringFormat("%.2d", _ArraySearch($aMonthNumberAbbrev, $aDate[1])) & "/" & $aDate[2] & " " & $aDate[3] EndFunc ;==>_GetUnixDate Enjoy!
      Realm
      Update: >Added some functionality and a suggestion from FireFox
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
    • ur
      By ur
      To get the current time stamp, I got the below code.
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #RequireAdmin ; Under Vista the Windows API "SetSystemTime" may be rejected due to system security $td = _Date_Time_GetSystemTime() $td = _Date_Time_SystemTimeToDateTimeStr($td) $td = StringReplace($td, " ", "_") $td = StringReplace($td, ":", "_") MsgBox(0,"",$td) But it is not giving the date or time of the timezone where the system is there.
      Please suggestt
    • Simpel
      By Simpel
      Hi,
      I wanted to use _GetLogonTime() by guinness (https://www.autoitscript.com/forum/topic/19370-autoit-wrappers/?do=findComment&comment=942069).
      #include <Date.au3> #include <Array.au3> ConsoleWrite(_GetLogonTime() & @LF) Func _GetLogonTime($sUserName = @UserName, $sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/ Local $aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sComputerName, "wstr", $sUserName, "dword", 11, "ptr*", 0) _ArrayDisplay($aRet) If @error Or $aRet[0] Then Return SetError(1, 0, False) Local $sHours = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", $aRet[4]), 18) DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aRet[4]) Return _DateAdd("h", "-" & $sHours, _NowCalc()) EndFunc ;==>_GetLogonTime It always returns false.
      I displayed $aRet:
      [0]|2221
      [1]|mycomputer
      [2]|myuser
      [3]|11
      [4]|0x0000000000000000
      $aRet[4] shouldn't be 0x0000000000000000 right? Any help?
      Regards, Conrad
       
    • DavidLago
      By DavidLago
      Hello. 
      I have 5 DCs, and I need to create a scheduled task to run a script that will test the authentication time for each one of them, once every minute. (Then I'll use it within a log analyser to create graphics).
      I came up with a script using the great AD UDF (by water). First I tried using "for" and an array, but something was messing up the results, then I went for the dumb old fashioned way:
      #Include <ad.au3> #include <MsgBoxConstants.au3> Global $AdTestTime = "" Global $Timer1, $Timer2, $Timer3, $Timer4, $Timer5 = "" Global $sAD1 = "MYSERVER109" Global $sAD2 = "MYSERVER110" Global $sAD3 = "MYSERVER111" Global $sAD4 = "MYSERVER112" Global $sAD5 = "MYSERVER113" $Timer1 = Timerinit() _AD_Open("", "", $sAD1) _AD_Close() Local $fDiff1 = TimerDiff($Timer1) $Timer2 = Timerinit() _AD_Open("", "", $sAD2) _AD_Close() Local $fDiff2 = TimerDiff($Timer2) $Timer3 = Timerinit() _AD_Open("", "", $sAD3) _AD_Close() Local $fDiff3 = TimerDiff($Timer3) $Timer4 = Timerinit() _AD_Open("", "", $sAD4) _AD_Close() Local $fDiff4 = TimerDiff($Timer4) $Timer5 = Timerinit() _AD_Open("", "", $sAD5) _AD_Close() Local $fDiff5 = TimerDiff($Timer5) MsgBox(0,"", "MYSERVER109=" & $fDiff1) MsgBox(0,"", "MYSERVER110=" & $fDiff2) MsgBox(0,"", "MYSERVER111=" & $fDiff3) MsgBox(0,"", "MYSERVER112=" & $fDiff4) MsgBox(0,"", "MYSERVER113=" & $fDiff5) Still, something is off here. 
      The first AD to be tested is always the slowest one, by far, like 20 times slower. Then I started to suspect that the first one starts the "negotiation", and the following ones ride the gravy train.
      If I repeat the first code twice, All servers seem to have a similar result.
      $Timer1 = Timerinit() _AD_Open("", "", $sAD1) _AD_Close() Local $fDiff1 = TimerDiff($Timer1) $Timer1 = Timerinit() _AD_Open("", "", $sAD1) _AD_Close() Local $fDiff1 = TimerDiff($Timer1) $Timer2.... Am I right?
      Also, is there a better way to test the authentication time?
      Thanks for the help.
      - Dave