The function time () returns the current calendar time, i.e., the number of seconds elapsed since 00:00:00 hour January 1, 1970 GMT (or gmt are used alternatively) up to the execution of the function. The function prototype is written as follows:
time_t time (time_t *Timeptr);
If Timeptr is not NULL, the return value gets stored in the memory pointed to by Timeptr. If unsuccessful, it returns a negative value.
Illustrates the application of function time () .
#include <stdio.h> #include <time.h> void main() { time_t Time; Time = time(&Time); clrscr(); printf("Time = %u\n", Time); }
The number given in the output represents the number of seconds since 00:00:00 hours 01 January1970 GMT up to the execution of this program. In the following sections, we shall discuss the different conversion functions that convert the output of time () function into string representing day, date, hours, min, sec, year, etc.