On Sun, 11 May 2003 19:24:47 +0100, "Allan Bruce"
Quote:
>Hi there,
>Is there a way I can get the date and time in c?
>I know how to get the proceessor time with time_t(&now);
>But I want to get something so that I can have the date, and the time in
>hours, mins, secs.
>Any suggestions?
The library funtions localtime() and gmtime() will convert a time_t
value into a structure with the various parts.
Libary functions asctime() and strftime() are convenient ways to turn
the stuct tm into something printable.
#include <time.h>
#include <stdio.h>
int main ()
{
time_t now;
struct tm *now_tm;
char *now_text;
time (&now);
now_tm = localtime (&now);
now_text = asctime (now_tm);
fputs (now_text, stdout);
return 0;
Quote:
}