Re: [ROOT] SetTimeOffset

From: Robert Hatcher (rhatcher@SLAC.stanford.edu)
Date: Thu Jan 25 2001 - 21:42:26 MET


On Thu, 25 Jan 2001, Damir Buskulic wrote:

> The time you have to use is the UTC time, which is expressed in seconds
> since a starting point, back in the seventies. There exists a routine in
> C called strptime that does just this, convert a string describing a
> time in human readable form, but it is not known to the interpreter
> since it doesn't seem to be standard C/Posix.
> This is unfortunate and I acknowledge it. There are basically two ways
> to circumvent this.
>
> 1) Make a structure of type struct tm which is a standard structure
> containing time information, fill it and convert it :
>
> #include <time.h>
> struct tm* stime;
> stime = new tm;
> stime->tm_sec=0; // seconds (0-61)
> stime->tm_min=0; // minutes (0-59)
> stime->tm_hour=0; // hours after midnight (0-23)
> stime->tm_mday=1; // day of the month (1-31)
> stime->tm_mon=0; // month since january (0-11)
> stime->tm_year=101; // year since 1900
> stime->tm_wday=0; // day of the week (0-6)
> stime->tm_yday=0; //number of the day in the year (0-365)
> stime->tm_isdst=0; // summer/winter hour flag
>
> my_time = mktime(stime);
>
> That's it !

Be careful here. The function "mktime" converts from *local* time in
a tm struct to a time_t where time_t is seconds since Epoch
(1970-1-1 00:00:00) UTC.  If you have a UTC in terms of
yr,mon,day,hour,min,sec you must correct for the local timezone offset
before calling "mktime" (add or subtract from the appropriate fields).

-robert

Robert W. Hatcher   |  rhatcher@slac.stanford.edu
Research Associate  |  650.926.3171  [FAX 4001 or 3587]
Stanford University |  PO Box 4349, MS #63, Stanford CA 94309



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:34 MET