Getting GMT-Time with WebRequest()

 

Hello,

I would like to add the option for getting the GMT-Time via WebRequest. On my VPS the MT4-inbuilt GMT-option does not work correctly.


I have some code, but would ask for some help. The code give me a result with no information about the GMT.

What should I change? I cannot get my head around it.

Thanks for some advices in advance.


string Read_URL(string _url,bool ShowErrorMessage) {
string cookie=NULL;
string headers="";
char post[];
char Read_URL_Result[];
int res;
string TextResult="-1";

ResetLastError();

//--- download html-pages
int timeout=5000; //--- timeout less than 1,000 (1 sec.) is insufficient at a low speed of the Internet

res=WebRequest("GET",_url,cookie,NULL,timeout,post,0,Read_URL_Result,headers);
int last_error=GetLastError();
//Read_URL_ErrorCode = last_error;
//--- error checking
if(res==-1) {
   if(last_error==4060 || last_error==4014) {
      if(ShowErrorMessage)
      Print(" Web request not allowed:",ErrorDescription(last_error));
   } 
   else {
      if(ShowErrorMessage)
      Print(" Web request failed:",ErrorDescription(last_error));
   }
   
   return TextResult;
} 
else {
   //--- successful
   if(ArraySize(Read_URL_Result)>0)
   TextResult=CharArrayToString(Read_URL_Result);
   else
   Print(ErrorDescription(last_error));
   return TextResult;
}
return TextResult;
}

Print(Read_URL("https://www.worldtimeserver.com/current_time_in_UTC.aspx",true));


Result:


<!DOCTYPE html>

<html lang="en">

<head><meta charset="utf-8" /><title>

Current local time in (UTC/GMT)

</title>

     <style type="text/css">

        .ico {

  display: inline-block;

  background-repeat: no-repeat;

  background-image: url('/img/sprite-s33c612617c.3.png');

}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {

  .ico {

    background-image: url('/img/sprite-retina-s509d95ead6.png');

  }

}

.ico.ico-fa {

  background: n



 

This webpage is using javascript to update time. Its better if you use some other simple standard service.


However if you still want to use this page look care fully time in there in webpage.

 
Florian Riedrich:

Hello,

I would like to add the option for getting the GMT-Time via WebRequest. On my VPS the MT4-inbuilt GMT-option does not work correctly.

What is the problem with TimeGMT() ?

 
Farrukh Aleem:

This webpage is using javascript to update time. Its better if you use some other simple standard service.


However if you still want to use this page look care fully time in there in webpage.

What kind of service do you think of? 
 
Alain Verleyen:

What is the problem with TimeGMT() ?


I cannot change the windows clock of my VPS. And this influences somehow with the gmt calculation. 

The customer service of the VPS provider won't help. 
 
Florian Riedrich:

I cannot change the windows clock of my VPS. And this influences somehow with the gmt calculation. 

The customer service of the VPS provider won't help. 

Why would you want to change the VPS clock ?

TimeGMT() is supposed to return the GMT time, whatever the VPS windows clock.

 
Alain Verleyen:

What is the problem with TimeGMT() ?

Authai Thomthong
 
Alain Verleyen:

Why would you want to change the VPS clock ?

TimeGMT() is supposed to return the GMT time, whatever the VPS windows clock.

I know what you mean. And I really don't understand it as well. I made a picture from my local PC and VPS at same time with the same EA

Have a look

GMT was 17:55 when I made the picture

Files:
wrong_GMT.jpg  61 kb
 
Florian Riedrich:

I know what you mean. And I really don't understand it as well. I made a picture from my local PC and VPS at same time with the same EA

Have a look

GMT was 17:55 when I made the picture

Yeah, that effectively means the VPS clock (Timezone/DST) is not set correctly.
 
Alain Verleyen:
Yeah, that effectively means the VPS clock (Timezone/DST) is not set correctly.

Yes. And when I try to change it, after 1 hour the clock is set back to another time. And I cannot stop the syncronisation.

The customer support won't help me.

So I thought to get the GMT from the internet. .... That's why I wanted to implement the code above. But I would need some more hints to implement it correctly.

 
Florian Riedrich:

Yes. And when I try to change it, after 1 hour the clock is set back to another time. And I cannot stop the syncronisation.

The customer support won't help me.

So I thought to get the GMT from the internet. .... That's why I wanted to implement the code above. But I would need some more hints to implement it correctly.

For example.
https://stackoverflow.com/questions/50885249/how-to-get-gmt-by-using-google-time-zone-api

There are others API available.

How to Get GMT by using Google Time Zone API
How to Get GMT by using Google Time Zone API
  • 2018.06.16
  • Paramjeet Singh
  • stackoverflow.com
I want to retrieve GMT(5.5) of India or same like this for other Country. Below is my code where I used Google Time Zone API and the coming response is on dstoffset, rawOffset, status, timeZoneId, timeZoneName. My question is how to get GMT (5.5) Thank you