Determining a City Time

Back to topics list To post a new topic, please log in or register
avatar
164
rod178 2015.01.11 15:28
 

Has anyone a code snippet to share that can pull the current  time of a city from some available server (whatever that may be) , including dst if applicable.

 

This information is obviously available from many servers eg  http://www.timeanddate.com/clocks/free.html       http://www.timeanddate.com/services/api/     the issue is  the most effectice method of extracting the data and importing into MT4. 

 

 

 

 

 

avatar
1211
deysmacro 2015.01.11 15:37 #
 
Maybe you show us first and usually others might improve it. If it is not that hard.
avatar
164
rod178 2015.01.11 15:45 #
 
deysmacro:
Maybe you show us first and usually others might improve it. If it is not that hard.

 

 

 

API call to server 

 

    http://api.timezonedb.com/?zone=Australia/Melbourne&key=<Your_API_Key>

<?xml version="1.0" encoding="UTF-8"?>
<result>
    <status>OK</status>
    <message></message>
    <countryCode>AU</countryCode>
    <zoneName>Australia/Melbourne</zoneName>
    <abbreviation>EST</abbreviation>
    <gmtOffset>39600</gmtOffset>
    <dst>1</dst>
    <timestamp>1321217345</timestamp>

</result> 

 

Question" best approach to make the call from within MT4 and import the data 

avatar
164
rod178 2015.01.11 16:20 #
 
rod178:

 

 

 

API call to server 

 

    http://api.timezonedb.com/?zone=Australia/Melbourne&key=<Your_API_Key>

<?xml version="1.0" encoding="UTF-8"?>
<result>
    <status>OK</status>
    <message></message>
    <countryCode>AU</countryCode>
    <zoneName>Australia/Melbourne</zoneName>
    <abbreviation>EST</abbreviation>
    <gmtOffset>39600</gmtOffset>
    <dst>1</dst>
    <timestamp>1321217345</timestamp>

</result> 

 

Question" best approach to make the call from within MT4 and import the data 

 

Using JavaScript Object Notation via  browser

 http://api.timezonedb.com/?zone=Australia/Perth&format=json&key= myAPIkey

=>  {"status":"OK","message":"","countryCode":"AU","zoneName":"Australia\/Perth","abbreviation":"AWST","gmtOffset":"28800","dst":"0","timestamp":1421017908}

OR

 http://api.timezonedb.com/?zone=Europe/London&format=json&key=myAPIkey

=>  {"status":"OK","message":"","countryCode":"GB","zoneName":"Europe\/London","abbreviation":"GMT","gmtOffset":"0","dst":"0","timestamp":1420989442} 

OR (this time note dst)

http://api.timezonedb.com/?zone=Australia/Sydney&format=json&key=myAPIkey

 =>  {"status":"OK","message":"","countryCode":"AU","zoneName":"Australia\/Sydney","abbreviation":"AEDT","gmtOffset":"39600","dst":"1","timestamp":1421029111}

 

Some work on a JSON parser link  https://www.mql5.com/en/code/11134

and XML parser    https://www.mql5.com/en/articles/1366   

                          https://www.mql5.com/en/code/1998 

 

 

Question is how to send and import  result into MT4 string variable. 

Is it better to import XML or JSON

 

 

 

 

Back to topics list  

To add comments, please log in or register