time zone problems

time zone problems

Oron Peled oron at actcom.co.il
Sun Mar 29 20:22:08 IDT 2009


(oops, the mailing list wasn't addressed in previous copy).

Erez:
> struct tm time_str;
> ...
> int d=timegm(&time_str)-timelocal(&time_str);
> printf("%d\n",d);
> 
> 
> prints 7200 (which is 2*3600 -> two hours).
> 
> 
> any idea ?
> or in in other words, how the f@#k i get the offset from GMT c-code ?

glibc-specific solution is easy:

        struct tm       *tm;
        time_t          t;

        t = time(NULL);
        tm = localtime(&t);
        printf("OFF=%ld\n", tm->tm_gmtoff);

My system output:
        OFF=10800 # this is 3 hours


-- 
Oron Peled                                 Voice: +972-4-8228492
oron at actcom.co.il                  http://www.actcom.co.il/~oron
"Simplicity is prerequisite for reliability."
                        -- Edsger Wybe Dijkstra





More information about the Linux-il mailing list