I want to get GMT offset automatically in my expert, i tried using this code but i ain't sure its working like it should be...
I don't think this is correct, please how do i get the correct GMT offset?
double ServerGmtOffsetHours=(TimeCurrent()-TimeGMT() +1800 )/3600;
I figured out i could do it like this, but can someone else test this if it should be working in all Timezones.
int GMT = TimeHour(TimeGMT()) & 0xFFFF;
int res = in_ho - GMT;
This will return the GMT Offset, it does that correctly on my PC using MetaQuotes-Demo, but i wanna be sure if it will be cool in all timezones...
Definitely it is not! You forget to consider that your pc clock might be wrong by a couple of minutes and that TimeCurrent() due to the latency caused by the internet is always a bit behind the correct time!
The int-cast - if I am right - always returns the lowest integer number not the nearest! WHRoeder's solution covers all that and its a lot simpler!
If you need India's fractions and you are sure the worst inaccuracy of both clocks is less than 7 minutes you can change his formula to :
double ServerGmtOffsetHours=(TimeCurrent()-TimeGMT() + 900 )/1800;
To add comments, please log in or register