Format
#include <time.h>
time_t time(time_t *timeptr);
Language Level: ANSI
Threadsafe: Yes.
Description
The time() function determines the current calendar time, in seconds.
Return Value
The time() function returns the current calendar time. The return value is also stored in the location that is given by timeptr. If timeptr is NULL, the return value is not stored. If the calendar time is not available, the value (time_t)(-1) is returned.
Example that uses time()
This example gets the time and assigns it to ltime. The ctime() function then converts the number of seconds to the current date and time. This example then prints a message giving the current time.
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t ltime;
if(time(<ime) == -1)
{
printf("Calendar time not available.\n");
exit(1);
}
printf("The time is %s\n", ctime(<ime));
}
/****************** Output should be similar to: ****************
The time is Mon Mar 22 19:01:41 2004
*/
Related Information