#: 6731 S3/Languages
16-Sep-90 11:24:25
Sb: #localtime problem
Fm: Ken Drexler 75126,3427
To: All
I need some help with localtime() in the Kreider library. I need to use it to
break down the value returned by time() into months, days and years. The only
problem is that the data returned is in the tm structure is ALWAYS March 6,
2106.
Is there a bug in localtime? or have I missed something?
Here is my code and a dump of the output:
#include
main()
{
long curtime; /* current date time */
struct tm *t, tim; /* tim for sizeof */
pflinit(); /* enable long printing */
curtime = time( (long *) 0);
printf("curtime: %ld, curtime/86,400: %ld\n",curtime,curtime/86400);
t = localtime( curtime );
printf("tm_sec: %d, tm_min: %d, tm_hour: %d, tm_mday: %d, tm_mon: %d,
tm_year: %d\n",
t->tm_sec, t->tm_min, t->tm_hour, t->tm_mday, t->tm_mon,
t->tm_year);
_dump("tm:\n",t, sizeof(tim) );
}
OUTPUT: curtime: 653435281, curtime/86,400: 7562 tm_sec: 15, tm_min: 28,
tm_hour: 6, tm_mday: 6, tm_mon: 2, tm_year: 206 tm:
1 2 3 4 5 6 7 8 9 a b c d e f 0 123456789abcdef0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---------------0211: 00
0f 00 1c 00 06 00 06 00 02 00 ce 00 00 00 24 ...........N...$ 0221: 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Has anyone else had this problem? What am I doing wrong?
(I also note that the heading on _dump is wrong and the function sends its
output to stderr not stdout as the clib documents say.)
Thanks for the help.
There are 2 Replies.
|