Home >>C Time Library Function >C time() function

C time() function

C time() function

C time() function is used to return the time since the Epoch measured in seconds. If the seconds are not NULL then the return value is also stored in variable seconds. This function is defined in <time.h> header file.

Syntax:
time_t time(time_t *t)

Parameters:-

secondsāˆ’ It is the pointer to an object of type time_t, where the seconds value will be stored.

Here is an example of time() function:

#include <stdio.h>
#include <time.h>
int main () 
{
time_t seconds;
seconds = time(NULL);
printf("Hours since January 1, 1970 = %ld\n", seconds/3600);
return(0);
}

Output:
Hours since January 1, 1970 = 440819

No Sidebar ads