RE: datetime.e

new topic     » goto parent     » topic index » view thread      » older message » newer message

>===== Original Message From sephiroth _ <euman2376 at yahoo.com> =====
>
>i just tried a little program in C. here's the source:
>
>#include <time.h>
>#include <stdlib.h>
>#include <stdio.h>
>
>int main (int argc,char **argv) {
>  struct tm *t;
>  long thetime;
>  if (argc==1) return 0;
>  thetime=strtoul(argv[1],'\0',10);
>  t=localtime(&thetime);
>  printf("%d/%d/%d %d:%02d:%02d\n",t->tm_mon+1,t->tm_mday,t->tm_year,
>                                   t->tm_hour,t->tm_min,t->tm_sec);
>  return 0;
>}
>
>oddly enough, when you run it with the argument 0, it prints "1/1/1969
>19:00:00". call me crazy, but doesn't that sound like new year's day
>1969, 9 PM? either something is wrong with my linux box, or something is
>wrong with the docs where you got the exact date of the epoch

Hi,

I compiled up this C program on HP-UX 10.20 and ran it with an argument of 0 
and got:

    1/1/70 0:00:00

But they I did this:

    TZ=EST5
    export TZ

and re-ran the program and got:

    12/31/69 19:00:00

I then tried:

    TZ=PDT7
    export TZ

and got:

    12/31/69 17:00:00

Finally setting back to:

    TZ=GMT0
    export TZ

gives:

    1/1/70 0:00:00

so the C program is getting the localtime by using the TZ (time zone) 
environment variable - does this explain the anomoly?  Can you try a similar 
test on Windows?

Regards,

FP.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu