setTimeOffset does not work correctly


I have been using TAxis->setTimeFormat(#splitline{%H:%M:%S}{%m/%d/%y}%F1970-01-02 02:00:00) to set the time on the xaxis. There appear to be several things wrong with the conversion. All of the times I am plotting are epoch times. The time zone I am converting to is +13 during DST and +12 normally. First, when I use the beginning epoch time (1970-01-01 00:00:00), The conversion is 12 hours behind the actual time. Secondly, when I change the time time format offset from 1970-01-01 00:00:00 to 1970-01-02 00:00:00, the time only changes 23 hours not 24. Finally, there are other changes in the time. I have data from march and may. Somewhere in there, DST ended, so the time zone changed from +13 to +12. I would expect the times to be an hour ahead, but instead they were two hours ahead. I am guessing that sometime between march and may the time conversion went 25 hours in one day. Has anyone seen this problem before or see something that I am doing wrong?



The details about time axis on this page: … time-units
I guess you saw it.
Can you send a small macro reproducing the problem ?
have you tried to use the GMT option ?

Hello again,

I have pinned downed some things that are strange/don’t seem to work. First of all, this is the script I used to create the sample graphs:

void timeTest(){
	Int_t x[] = {1268530000, 1268535000};
	Int_t y[] = {1,2};
	Int_t n = 2;
	TGraph *gr1 = new TGraph (n, x, y);
	gr1->GetXaxis()->SetTimeFormat("#splitline{%H:%M}{%m\/%d}");//%F1970-01-01 12:00:00");

This time I tried to set my times to GMT time.

The first thing I found is that when using the manual time offset ( %F1970-01-01 12:00:00 ), local DST is taken into account. This means that 02:00:00 doesn’t exist on the graph. I think this can be traced back to strftime() which uses local time zone information. Still thought, that doesn’t explain why I have to offset 12 hours to get gmt time.

Next, I tried the gmt option with gr1->GetXaxis()->SetTimeOffset(0,“gmt”);
The time was still 5 hours behind what says it should be. My only guess is that that is a time zone difference (because I am located in the -5 time zone). Is this correct?

Finally, I noticed that changing the gmt offset does not work correctly. Adding 25 hours with (90000,“gmt”); offsets the time 24 hours. Offsetting the time anything less than 3600 has no effect at all, and anything over 3600 it offsets by that number - 3600.

Any idea what is going on?


The following macro gives me the attached plot.

void timeTest(){
   Double_t x[2], y[2];

   // Define the lowest graph's limit as 2010, January 10th 00:00
   TDatime T1(2010,01,10,00,00,00); 
   x[0] = T1.Convert();       
   y[0] = 1.,

   // Define the lowest graph's limit as 2010, January 10th 05:00
   TDatime T2(2010,01,10,05,00,00);
   x[1] = T2.Convert();       
   y[1] = 2.,

   TGraph *gr1 = new TGraph (2, x, y);


I tried your example:

root [0] TDatime T1(2010,01,10,00,00,00);
root [1] int i = T1.Convert();       
root [2] cout<<i
1263103200(class ostream)140638169647968
root [3]

I put 1263103200 in and the result was GMT: Sun, 10 Jan 2010 06:00:00 GMT (see attachment).

So either there are two different standards or one of the two methods does not work correctly. Could it be from the fact that root seems to use 1995 as a base for TDatime, whereas the epoch converter uses 1970?

I tried to experimentally find the right time for 1263103200 (the time root gave me for 00:00:00 January 10, 2010) :

; 1263103200%60 //Seconds
; 1263103200/60
; 21051720%60 //Minutes
; 21051720/60
; 350862%24 //Hours

Shouldn’t it be 0 hours?


In my example I am using TDatime as recommended in the howto about time axis, and it is working. I guess the difference comes from the fact that ROOT has a different reference date.

Ok, if I use T1.convert(true), then it is supposed the convert from gmt time (instead of local time, as it was doing before). However, the time from is still 12 hours off… GMT: Sun, 10 Jan 2010 12:00:00 GMT

I suppose this would work IF I use the setTimeOffset(0,“gmt”) to actually use gmt time, not local time. As you showed before when you converted 1/10/2010 to a local timestamp then back to 1/10/10 again correctly, setTimeOffset(0,“gmt”), assumes all times are in local time…


Hello again,

I found the solution. I set the environment variable TZ in my shell to NZ (export TZ = NZ). Then I used setTimeOffset (0,“gmt”) and it set the time correctly to local south pole time (although DST at the pole is not taken into account).


Thanks to have post the solution.
Note that on my machine TZ is not defined.

It’s not defined on mine (Ubuntu 10.04) either until I export it. However, date command is different from before and after I set the variable, so it should work.