Formatting TDatime output

Is it possible to manipulate the format TDatime methods return date/time information in? What I am interested in particular at this moment is to have the hour padded with a zero if it’s smaller than 12 (I use these time stamps for naming output files and the lack of padding disrupts the order sometimes), but I expect other capabilities of this kind would also be useful to the general ROOT public.

Can you send a small script showing what you are doing right now ?

Huh, I have forgotten about posting this question :slight_smile: Let me clarify.

I access the date & time information using a TDatime object. The two ways I know in which such objects can return this information are:

  • as integers (with GetDate() and GetTime()), which is what I use now - see the example below; this makes it easy to obtain unique timestamps, but since a number can only become zero-padded at the beginning after it’s been converted to a string, getting a 000000 instead of plain 0 (the most extreme case) would require fooling around with sprintf() or stream strings;
  • as a fixed-format character string (using AsString()); this takes care of the padding but the fact ctime() is used here seems to rule out the possibility of altering the method’s output format and thus makes it necessary to perform string mangling.

What I would like to know is whether there is some non-obvious way of obtaining a custom-formatted, e.g. strftime() style, time-stamp string from ROOT? And failing that, is there a chance of getting such a feature in the future?

For the record, here is what I do at present:

                TString tmpOF;
                TDatime *tm = new TDatime;
                tmpOF = "c2_";
                tmpOF += tm->GetDate();
                tmpOF += '-';
                tmpOF += tm->GetTime();
                tmpOF += '_';
                tmpOF += gSystem->Getenv("HOSTNAME");
                tmpOF += '-';
                tmpOF += gSystem->GetPid();
                tmpOF += ".root";
                delete tm;