Unix time, UTC time and Time offset

You can try this one:

{
   TDatime da(2009,10,9,18,0,0);  
float t = da.Convert();
   float x[3];
   x[0] = t;
   x[1] = 3600+t;
   x[2] = 3600*2+t;
   float y[3] = {1.5, 3.0, 4.5};

   TGraph* g = new TGraph(3,x,y);

   g->Draw("APL");
   g->SetMarkerStyle(20);

   g->GetXaxis()->SetTimeDisplay(1);
   g->GetXaxis()->SetTimeOffset(0,"gmt");             
   g->GetXaxis()->SetTimeFormat("%H-%M-%S");
}

that is gmt

thank you for your reply,
although I’m sorry to say I don’t get it.

I moved from TDatime class to TTimeStamp following this comment in the TDatime class description:

[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.
[/quote]

and actually my life improved a lot as TTimeStamp works actually much better.
[The times I am displaying are gps timestamps the daq puts into the events.]

Anyhow I tried your code and I see a 1h shift compared to the times you are entering.
I also tried to use Convert(1) instead of Convert() as from the manual that seems to be needed when you want UTC time, but in that case the shift becomes 3h!

I revert back to the original problem:
TAxis::SetTimeOffset() only works if t>3600. For t<3600 the offset is put to 3600.
If possible I would need to put offset to 0 in order to use my time_t times without having shift them. If not I will shift them.
Thank you
Davide

To me the core for the problem is that root does not support the negative offsets that are required to go from local unix time (including summer time) to UTC.

If that was supported then this would do it (this is python but mktime exists also in C):

import time
DT= (time.mktime(time.gmtime(int(intime))[0:-1]+(-1,))-int(intime))
someaxis.SetTimeOffset(DT)

‘intime’ here is the start of your axis.

I guess to really get local->UTC right it has to be supported by root, since with the offset method you miss DST changes taking place within your axis

thank you but I do not use local time anywhere. All my times are UTC.
davide