Barth
October 11, 2010, 3:32pm
1
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
couet
October 11, 2010, 3:47pm
2
With which root version ? on which machine ?
couet
October 11, 2010, 4:28pm
3
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");
}
Barth
October 11, 2010, 4:34pm
4
Hi,
Indeed…
Sorry, I overcomplicated
Cheers
Barth
Barth
October 12, 2010, 7:12am
5
Hum… Actually the year is wrong with your example : 2035
This is reproduceable on lxplus with ROOT 5.26.00b.
Cheers,
Barth
couet
October 12, 2010, 1:51pm
7
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");
}
Barth
October 12, 2010, 2:21pm
8
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
couet
October 12, 2010, 2:30pm
9
Actually the fact it is in second is explained here:
root.cern.ch/drupal/content/how- … time-units