time(2 or 3)
Jay Batson
jay at isis.UUCP
Thu Jun 12 01:41:26 AEST 1986
In article <337 at lll-lcc.UUcp> zingman at lll-lcc.UUcp (Jonathan Zingman) writes:
> ... I want to use the
>routine localtime, which breaks down a pointer "such as returned by
>time(2)." Later in the same section of the manual it says "SEE ALSO
^^^^^^^ I would hope you can find it - I can't imagine you'd have
ctime(3) and _not_ have time(2). look again, or in you online man.
>time(3)" I can't find time in either of those sections, and my guesses
^^^^^^^ my manual doesn't say this, but then again, I'm still on v7...
>at how to call it so far have not worked....
Easy.
#include <time.h>
some_fcn(params)
sometype params;
{
long somevar1;
struct tm *somevar2;
/* or... */
struct tm *somevar2, *localtime();
/* depending on whether or not your <time.h> already defines
localtime or not... */
/* ok, first get ahold of the number of seconds since Jan 1, 1970 */
somevar1 = time(0);
/* ok, now pass localtime a pointer to somevar1. localtime will
will go about declaring the structure it will use, and fill the
structure up with appropriate info - we just want to expect to
be returned a pointer to what localtime comes up with */
somevar2 = localtime(&somevar1); /* note &somevar1 passes a pointer */
/* ^^^ pointer recv'g what retd */ /* to what we got from time(2) */
/* ok, now to get at what localtime has prepared for us, here
is an example */
printf("The current time is: %2d:%2d:%2d (on a 24 hour clock)\n",
somevar2->tm_hour, somevar2->tm_min, somevar2->tm_sec);
} /* end some_fcn */
See? Easy.
--------
"OK, so now, after it gets dark Lancelot and I will jump out of the rabbit, and
take the castle by supr........ oh."
Jay Batson
{seismo,hplabs}!hao!isis!jay
More information about the Comp.lang.c
mailing list