See script
//+------------------------------------------------------------------+ //| LocalTime.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #import "kernel32.dll" void GetLocalTime(int& TimeArray[]); void GetSystemTime(int& TimeArray[]); int GetTimeZoneInformation(int& TZInfoArray[]); #import //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { int TimeArray[4]; int TZInfoArray[43]; int nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec; string sMilliSec; //---- GetSystemTime(TimeArray); //---- parse date and time from array nYear=TimeArray[0]&0x0000FFFF; nMonth=TimeArray[0]>>16; nDay=TimeArray[1]>>16; nHour=TimeArray[2]&0x0000FFFF; nMin=TimeArray[2]>>16; nSec=TimeArray[3]&0x0000FFFF; //---- format date and time items string time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec); Print("System time is: ",time_string); //---- GetLocalTime(TimeArray); //---- parse date and time from array nYear=TimeArray[0]&0x0000FFFF; nMonth=TimeArray[0]>>16; nDay=TimeArray[1]>>16; nHour=TimeArray[2]&0x0000FFFF; nMin=TimeArray[2]>>16; nSec=TimeArray[3]&0x0000FFFF; nMilliSec=TimeArray[3]>>16; //---- format date and time items sMilliSec=1000+nMilliSec; sMilliSec=StringSubstr(sMilliSec,1); time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec); Print("Local time is: ",time_string,":",sMilliSec); //---- shift with daylight savings int gmt_shift=0; int ret=GetTimeZoneInformation(TZInfoArray); if(ret!=0) gmt_shift=TZInfoArray[0]; Print("Difference between your local time and GMT is: ",gmt_shift," minutes"); if(ret==2) gmt_shift+=TZInfoArray[42]; Print("Current difference between your local time and GMT is: ",gmt_shift," minutes"); //---- GMT datetime local_time=StrToTime(time_string); Print("Greenwich mean time is: ",TimeToStr(local_time+gmt_shift*60,TIME_DATE|TIME_SECONDS)); //---- winter time (nYear remains the current) nYear=TimeArray[17]&0x0000FFFF; nMonth=TZInfoArray[17]>>16; nDay=TZInfoArray[18]>>16; nHour=TZInfoArray[19]&0x0000FFFF; nMin=TZInfoArray[19]>>16; nSec=TZInfoArray[20]&0x0000FFFF; time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec); Print("Standard time is: ",time_string); //---- summer time (nYear remains the current) nYear=TimeArray[38]&0x0000FFFF; nMonth=TZInfoArray[38]>>16; nDay=TZInfoArray[39]>>16; nHour=TZInfoArray[40]&0x0000FFFF; nMin=TZInfoArray[40]>>16; nSec=TZInfoArray[41]&0x0000FFFF; time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec); Print("Daylight savings time is: ",time_string); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec) { string sMonth,sDay,sHour,sMin,sSec; //---- sMonth=100+nMonth; sMonth=StringSubstr(sMonth,1); sDay=100+nDay; sDay=StringSubstr(sDay,1); sHour=100+nHour; sHour=StringSubstr(sHour,1); sMin=100+nMin; sMin=StringSubstr(sMin,1); sSec=100+nSec; sSec=StringSubstr(sSec,1); //---- return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec)); } //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
while LocalTime() - ie PC time - and CurTime() - ie server time - are available in MT4, this does nothing to help timed EAs, eg execute orders at 00:00 GMT, or only operate during European session.
Can I suggest that a GMTtime() function is added to MT4? This would either need to refer to the timezone defined by the broker, or could use the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation