Something is definitely wrong with TimeLocal()

 
I have this simple script that simply displays the TimeLocal() directly on the chart:

int start() {
//----
	ObjectDelete("CLOCK");
	ObjectCreate("CLOCK", OBJ_TEXT, 0, Time[5], Bid-5*Point );
	ObjectSetText("CLOCK", "!", 20, "Arial Black", EMPTY);
	ObjectSet("CLOCK", OBJPROP_COLOR, Yellow);

	while (ObjectFind("CLOCK") == 0) {
		Comment("\n",TimeToStr(TimeLocal(), TIME_SECONDS));
		ObjectSetText("CLOCK", TimeToStr(TimeLocal(), TIME_SECONDS), 20, "Arial Black", EMPTY);
		Sleep(250);
	}
	return(0);
}




The clock changes from GMT+0 to Computer's LocalTime depending on the timezone of the computer. Listed are some "Time Zones" and the corresponding clock

GMT+12 AuckLand, Wellington 11:00 (local time)
GMT+11 Magadan, Solomon Is. 23:00 (time of GMT+0)
GMT+10 Vladivostok 9:00 (local time)
GMT+9:30 Darwin 23:00 (time of GMT+0)
GMT +8 Perth 7:00 (local time)
GMT+8 Singapore 23:00 (time of GMT+0)
GMT+8 Ulaan Bataar 7:00 (local time)
GMT+8 Beijing 23:00 (time of GMT+0)
GMT+2 Cairo 1:00 (local time)
GMT+0 London 23:00 (time of GMT+0)
GMT-5 Eastern Time 18:00 (local time)
.
.
.

TimeLocal gives out either GMT+0 or localtime depending on the "TimeZone" selected on the computer.

It is definitely a bug!

 
Please do not mix local time and system time. Local time depends on time zone always - this is local time
 
Can you please do the following to confirm the bug?

Step 1: Set your Timezone to US EST.
What is the TimeLocal() from MT4?

Step 2: Without changing time on your computer, change the Timezone to GMT+8 Singapore.
What is the TimeLocal() from MT4?

Step 3: Without changing time on your computer, change the TimeZone to GMT+8 Beijing/HK.
What is the TimeLocal() from MT4?


The answers would be:
1. TimeLocal() = Time of Computer
2. TimeLocal() = Time of Computer
3. TimeLocal() = GMT+0 instead of GMT+8

As I said it is a bug.
 
To confirm this bug:

I have a friend in Florida (GMT-5 aka EST), a friend in Cairo (GMT+2), and I am in HK (GMT+8)

My computer time is currently 21:18:00
In Florida, computer time is 9:18:00
In Cairo, computer time is 15:18:00

The script above shows:
My Computer: 13:18:00
Florida Computer: 9:18:00
Cairo Computer: 15:18:00

So why is it that on my computer it is showing 13:18 instead of 21:18?

But when I change my Timezone (No change to time) to GMT+8 Perth, it now displays 21:18:00 and is now same with all the other 3 people...

TimeLocal() displays GMT+0 when I use Timezone HK, Singapore; but TimeLocal() displays GMT+8 when I choose Timezone Perth... I hope someone can explain this "special phenomenon"....
 
Sorry, I don't understand. Does time returned from TimeLocal function differ from computer clock?

 
Sorry, I don't understand. Does time returned from TimeLocal function differ from computer clock?


EXACTLY! TimeLocal() should be same with Computer Time, but on some TimeZones, it is not.

Change your Timezone to GMT+8 Beijing (where I am in) and see the difference. There are other timezones wherein its not same also as listed on my first post.

I have tested this on 4 of my computers (WinXP) and someone in Florida and Cairo have tested this as well.
 
Stop client terminal
Change TimeZone
Start client terminal
Check compare local time with computer clock

Use my script and please show screenshot

//+------------------------------------------------------------------+
//|                                                    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);
//----
   Print("TimeLocal function returns ",TimeToStr(TimeLocal()));
//----
   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));
  }
//+------------------------------------------------------------------+
 
As directed:

1. Close MT4
2. Change TimeZone to GMT+8 Beijing, HongKong
3. Open MT4
4. Login, run your script

This is what I see


Check that my Computer's Time is 9:59PM.
 
More clear. Thank You. We will think how fix it
 
I cannot reproduce
What the operating system do You use?
 
All my computers are WinXP Home and Pro; a friend in Cairo use WinXP too; and I dont know if my friend in Florida uses WinXP too - but I guess he is not using Vista yet.

When you try to reproduce, what timezone did you try?
GMT+8 Beijing, HongKong is giving me the problem. Other timezone is giving me error as well to name a few:
GMT-10 Hawaii
GMT-7 Arizona
GMT-6 Central America
GMT-6 Saskatchewan

I have build 202; build 203 is not available yet. I have tried this on all the MT4 brokers I could find: IBFX, NF, MIGFX, PFGFX, FXDD same result: TimeLocal() always displays GMT+0 instead of GMT+8 on my computers.