1 hour missing in my time axis

Hello,

When plotting against time, I have a shift of 1 hour. I am sure it is related to the GMT time but I am unable to find what is wrong.

  TGraph *tg = new TGraph();
  tg->SetMarkerStyle(3);
  tg->Draw("ap");
  TDatime now;
  tg->SetPoint(0, now.Convert(), 3);
  cout << "time now : " << now.AsString() << endl;
  tg->GetXaxis()->SetTimeDisplay(1);
  tg->GetXaxis()->SetNdivisions(-503);
  tg->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M:%S");
  tg->GetXaxis()->SetTimeOffset(0,"gmt");
  gPad->Modified();

This code will print the correct time, ie. the same as the ‘date’ command on the computer, let’s say 17:15, but the plot shows 16:15. I tried to use SetTimeOffset(1, “gmt”) but it doesn’t help (no change).

Any help welcome !
Thanks
Barth

With which root version ? on which machine ?

actually, no time offset makes it the way you want:

{
   TGraph *tg = new TGraph();
   tg->SetMarkerStyle(3);
   tg->Draw("ap");
   TDatime now;
   tg->SetPoint(0, now.Convert(), 3);
   cout << "time now : " << now.AsString() << endl;

   tg->GetXaxis()->SetLabelSize(0.03);
   tg->GetXaxis()->SetTimeDisplay(1);
   tg->GetXaxis()->SetNdivisions(-503);
   tg->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M:%S");
}

Hi,

Indeed…
Sorry, I overcomplicated :slight_smile:

Cheers
Barth

Hum… Actually the year is wrong with your example : 2035

This is reproduceable on lxplus with ROOT 5.26.00b.

Cheers,
Barth

I’ll check

It gives the right time if I do:

{
   TGraph *tg = new TGraph();
   tg->SetMarkerStyle(3);
   tg->Draw("ap");
   TDatime now;
   tg->SetPoint(0, now.Convert(), 3);
   cout << "time now : " << now.AsString() << endl;

   tg->GetXaxis()->SetLabelSize(0.03);
   tg->GetXaxis()->SetTimeDisplay(1);
   tg->GetXaxis()->SetNdivisions(-503);
   tg->GetXaxis()->SetTimeOffset(3600,"gmt");         
   tg->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M:%S");
}

Ok, so the time offset is necessary, and its first argument is in seconds not in hours as I thought. It might be nice to add a line about that in the documentation of the method, just to know the unit.

Thanks a lot for your help,
Barth

Actually the fact it is in second is explained here:
root.cern.ch/drupal/content/how- … time-units