Problem with Grabbing System Time
Brian Smith
Brian.Smith@PicoDyne.com
Sun Dec 20 20:22:00 GMT 1998
Not
sure I can tell you anything specific, but that date seems awfully close to the
UNIX epoch, or time zero.ÃÂ Perhaps you aren't adding an offset to get
todays date.
ÃÂ
Brian
ÃÂ
-ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ Brian S.
Smith -ÃÂ ÃÂ ÃÂ ÃÂ PicoDyne Corporation -ÃÂ Annapolis
Engineering Office -(v)410-266-8828 (fax)410-266-8872
-----Original Message----- From: owner-gnu-win32@cygnus.com
[mailto:owner-gnu-win32@cygnus.com] On Behalf Of
Dominia Sent: Sunday, December 20, 1998 11:32 AM To: gnu-win32@cygnus.com Subject:
Problem with Grabbing System
Time 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