Jump to content

Get time from other country


MyEarth
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Maybe this solution:

??

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

×
×
  • Create New...