how get GMT with werequest

 

i dont know why i have just  a datetime but not time gmt

some one can give help plz

//+------------------------------------------------------------------+
//|                                                   webrequest.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

int OnInit()
  {

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

string time0 = WorldtTimeServer(  )  ;
int time1 =    StringFind(  time0  ,"stdbias" );
datetime time2 = datetime(TimeToString(time1 )) ;


Comment(time2);

}

string  WorldtTimeServer(  ) 
  { 
  string headers;
  string cookie=NULL; 
   char post[],result[];

    
   int res; 
   string TXT;
//--- to enable access to the server, you should add URL "https://www.google.com/finance" 
//--- in the list of allowed URLs (Main Menu->Tools->Options, tab "Expert Advisors"): 
   string google_url="https://www.worldtimeserver.com/"; 
//--- Reset the last error code 
   ResetLastError(); 
//--- Loading a html page from Google Finance 
   int timeout=5000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection 
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);   ;
//--- Checking errors 
   if(res==-1) 
     { 
      Print("Error in WebRequest. Error code  =",GetLastError()); 
      //--- Perhaps the URL is not listed, display a message about the necessity to add the address 
      MessageBox("Add the address '"+google_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION); 
     } 
   else 
     { 
      //--- Load successfully 
      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result)); 
      //--- Save the data to a file 
      int filehandle=FileOpen("GoogleFinance.htm",FILE_WRITE|FILE_BIN); 
      //--- Checking errors 
      if(filehandle!=INVALID_HANDLE) 
        { 
         //--- Save the contents of the result[] array to a file 
         FileWriteArray(filehandle,result,0,ArraySize(result)); 
         //--- Close the file 
         FileClose(filehandle);

        int filehandle2=FileOpen("GoogleFinance.htm",FILE_READ|FILE_BIN);
         TXT=FileReadString(filehandle2,ArraySize(result));
         FileClose(filehandle2);
        }else{
         Print("Error in FileOpen. Error code =",GetLastError());
        }
     }

   return(TXT);
  }
 

What's that code ? A lot of references to google which have nothing to do with worldtimeserver.

Why do you want to get time from a web server at all ? GMT time is provided directly in MQL with TimeGMT().

 
Alain Verleyen #:

What's that code ? A lot of references to google which have nothing to do with worltimeserver.

Why do you want to get time from a web server at all ? GMT time is provided directly in MQL with TimeGMT().

yes i know  we have TimeGMT in MQL

but  i use news filter  i need upload GMT from webrequest 

 
Alain Verleyen #:

What's that code ? A lot of references to google which have nothing to do with worldtimeserver.

Why do you want to get time from a web server at all ? GMT time is provided directly in MQL with TimeGMT().

i have annother code but give the same thing  just the date of the day
string GrabWeb() {
string cookie=NULL;
string strUrl;
   string headers,ret;  
   char post[],result[];
   int res, timeout=5000;
   
   strUrl= "https://www.worldtimeserver.com/"; 
   
   res=WebRequest("GET",strUrl,cookie,NULL,timeout,post,0,result,headers); 
   if (res < 0) { 
        Alert("Web-Error: ",GetLastError()," (4060 ERR_FUNCTION_NOT_CONFIRMED/Url not allowed)" );
        return("");
   } 
   ret = CharArrayToString(result,0,-1);  
   return(ret);
}