Problem with Grabbing System Time

Dominia demoness@erols.com
Sun Dec 20 08:40:00 GMT 1998


Greetings,
I was having some trouble with porting a Unix application to
Windows in that the gettimeofday doesn't seem to be working correctly.
The larger program I am working with is returning:
Wed Feb 11 21:21:36 1970
as the current system time, but my system clock was set to:
Sun Dec 20 11:13:23 1998
when the "time" command was run.
I tried running the following snippet to check what actual time
my system was returning. It consistently returns dates from February of
1970.
3 1 11 21:33:39 70 ( this is equivalent to Wed Feb 11 21:33:39
1970 )
At least it's incrementing the clock, but I can't figure out
why it's not current. Is there something I am missing? Whatever it is,
I am just not seeing it. Is it my system? Is it me? What?? Any help would
be appreciated.
 
Thanks,
Paula
(The following was compiled via gcc on the command line with
just "gcc test.c" and then I ran ./a.out and got the results I reported
above.)
 
     #include <sys/types.h>
     #include <sys/time.h>
     main() {
         struct timeval
tp; struct timezone tzp;
         struct tm *lt;
         long secs1970;
         gettimeofday(&tp,
&tzp);
         secs1970= tp.tv_sec;
         lt = localtime(&secs1970);
         printf("%d
%d %d %d:%d:%d %d\n",
         lt->tm_wday,
lt->tm_mon,  lt->tm_mday,
         lt->tm_hour,
lt->tm_min,  lt->tm_sec, lt->tm_year
         );
     }



More information about the Cygwin mailing list