C Library Function - time()
Description
The C library function timet time(timet *seconds) returns the time since the Epoch (1970-01-01 00:00:00 UTC) in seconds. If seconds is not NULL, the return value is also stored in the variable seconds.
Declaration
Here is the declaration for the time() function.
time_t time(time_t *seconds)
Parameters
- seconds -- This is a pointer to a time_t object where the seconds value can be stored.
Return Value
Returns the current calendar time as a time_t object.
Example
The following example demonstrates the use of the time() function.
#include <stdio.h>
#include <time.h>
int main ()
{
time_t seconds;
seconds = time(NULL);
printf("Hours since 1970-01-01 = %ld\n", seconds/3600);
return(0);
}
Let's compile and run the above program, which will produce the following result:
Hours since 1970-01-01 = 373711