PDA

View Full Version : Getting the date and time in C



10-12-2001, 11:23 AM
Does anyone know how to get the date and time in C and then print it out to the screen?

11-12-2001, 02:45 AM
I haven't tried it but K&R says the functions are declared in time.h

11-12-2001, 09:18 AM
#include<time.h>
#include<stdio.h>

int main(void)
{
time_t timer;

timer=time(NULL);
printf('The current time is %s\n',asctime(localtime(&timer)));
return 0;
}