#property strict
#import "Wininet.dll"
int InternetOpenA(string, int, string, string, int);
int InternetConnectA(int, string, int, string, string, int, int, int);
int HttpOpenRequestA(int, string, string, int, string, int, string, int);
int InternetOpenUrlA(int, string, string, int, int, int);
int InternetReadFile(int, string, int, int& OneInt[]);
int InternetCloseHandle(int);
#import
string site1 = "http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?tz=America/New_York";
//string site2 = "http://http://localtimes.info/North_America/United_States/New_York/New_York/";
string site2 = "http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?tz=";
int NY_Diff,GMT_Diff;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
NY_Diff= Time_Offset(site1,83);
Print(NY_Diff);
}
//+------------------------------------------------------------------+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Major part of this code was done by maximo @ worldwide-invest.org
int Time_Offset(string site,int location)
{
string msg1 = "";
string msg2 = "";
int HOUR=100;
int Time_Diff;
int HttpOpen = InternetOpenA("HTTP_Test", 0, "", "", 0);
int HttpConnect = InternetConnectA(HttpOpen, "", 80, "", "", 3, 0, 1);
int HttpRequest = InternetOpenUrlA(HttpOpen, site, NULL, 0, 0, 0);
Comment ("Looking Time Offset");
int read[1];
string Buffer = " "; // 10 characters are read at a time
string page = ""; // join each 10 onto page string
int Nchars = 16000; // how many bytes to read to find GMT in HTML source
while (true)
{
InternetReadFile(HttpRequest, Buffer, StringLen(Buffer), read);
if (read[0] > 0) page = page + StringSubstr(Buffer, 0, read[0]);
else break;
Nchars = Nchars - StringLen(Buffer);
if (Nchars <= 0) break;
}
int index=StringFind(page, "Current Date and Time in", 0);
if (index > 0)
{
msg1 = StringSubstr(page,index+location,2);
//msg2 = StringSubstr(page,location+3,2);
msg2 = StringSubstr(page,index+location+6,4);
HOUR=StrToInteger(msg1);
if (HOUR>=0 && HOUR<=11)
{
if (msg2=="A.M.") HOUR=HOUR;
if (msg2=="P.M.") HOUR=12+HOUR;
}
}
if (HttpRequest > 0) InternetCloseHandle(HttpRequest);
if (HttpConnect > 0) InternetCloseHandle(HttpConnect);
if (HttpOpen > 0) InternetCloseHandle(HttpOpen);
if (HOUR==100) return (HOUR);
if (Hour()>=HOUR) Time_Diff=Hour()-HOUR;
if (Hour()<HOUR) Time_Diff=24-HOUR+Hour();
return (Time_Diff);
}