gStyle->SetTimeOffset() in GMT

in my ROOT script, I use timestamps created with TTimeStamp with are seconds since 1/1/1970 00:00:00.
Now, I don’t know how to set the correct offset to have proper times at the axis. I think the main problem is
the fact, that gStyle->SetTimeOffset() allways adds the difference of the local timezone to GMT.

Furthermore, the way I tried to use the format string does not help either.

The attached script shows the problem. I use version of ROOT (“5.26/00b”). The local timezone of my computer is CEST (UTC+2). The first and the third plot are one hour ahead of the local time, the second plot is one hour behind local time and one hour ahead of GMT. Surprisingly the fourth plot with the broken format string shows local time on the axis.

How do I set the time offset correctly?

Thanks in advance,
demoTimeAxis.C (1.7 KB)


The time axis usage is explained in details here: … time-units
I do not know (yet) if TTimeStamp is compatible with time axis.
All the examples in the HowTo are using TDatime.


PS: I am away for a few days. I will be back next Tuesday. Forgive me if you do get any answer to this question before next Tuesday.

thank you for pointing me to the given webpage. However, the page does not say anything about time zones, while the documentation of TDatime says:

[quote]This class has no support for time zones. The time is assumed
to be in the local time of the machine where the object was created.
As a result, TDatime objects are not portable between machines
operating in different time zones and unsuitable for storing the
date/time of data taking events and the like. If absolute time is
required, use TTimeStamp.

Using TTimeStamp results for me in the problems which I demonstrated in the script which is attached to my original post.

If I do this my axis start at 14:00 (I am at gmt +1):

void demoTimeAxis()

  TTimeStamp startTime(2010,07,21,13,0,0, 0, kTRUE);
  TTimeStamp stopTime (2010,07,21,15,0,0, 0, kTRUE);

  TH1F *h1  = new TH1F("h1" ,"h1",100, startTime.GetSec(), stopTime.GetSec() );


  h1->GetXaxis()->SetTimeFormat("%Hh%M %d/%m/%Y");


Thanks for looking at this topic again.

A time offset of (0, “gmt”) looks good to me, however in my timezone the axis starts at 1400 as well, but currently the timezone of my computer is gmt+2 (gmt+1 + 1hour DST).

[quote]$ date "+%Z (%z)"
CEST (+0200)
If I choose the date to be in january (no DST) the axis starts at 1400, too. In this case the time is correct.

My remaining questions are:

  • Is it intended that the time display ignores DST (not ignoring DST might create problems at beginning and end of DST)?
  • Is there something similar to the “gmt” option for TStyle::SetTimeOffset? Otherwise the offset has to be set for each histogram.
  • Is there a way to display the time on the axis in a given timezone (or at least in gmt/UTC)? It is actually quite unsatisfying to have plots which depend on the timezone of the computer, they are created on.

Cheers, Jörgen.

In principal it does take DST into account (look at the TGaxis code). But this code has been done by many people and each time we touch it some bad side effects are introduced and some backward incompatibilities are generated. So I am very reluctant to do any mods in the existing code.

The “gmt” option can be accessed only the way I showed you.

No, this doesn’t not exist. As I said any mods in this code produces bad side effects. A such extensions could be think only in the case of a global (re)-design.

O.k. after looking at some pieces the source code, I think I understand what you mean. Nevertheless even with your code I can only create plots with local time without DST. (Which are off by 1 hour in summer).

Finally, I found a workaround to create plots with UTC time on the axes and setting the time offset wrt. gmt in gStyle by setting the TZ environment variable to UTC. This can even be done from within any plot macro by calling gSystem->Setenv before doing any time-realated plots.



OK thanks for the input.