What is time() in C?
The time function is a C library function that returns the time since the Epoch (00:00:00 UTC, January 1, 1970) in seconds.
To use the time function, the time.h header file needs to be included in the program, as shown below:
#include <time.h>
Syntax
An object of thetime_t type is used for the function declaration as shown below:
time_t time(time_t *second)
Parameters
The function takes a single parameter (second) of the pointer type used to set the time_t object.
Return Value
The current time is returned in the time_t object type.
Example
The code below shows the use of the time function in C:
#include <stdio.h>#include <time.h>int main(){//Declare the time_t objecttime_t seconds;seconds = time(NULL);//Display the time in secondsprintf ("Seconds passed since Jan 1, 1970: %ld", seconds);return 0;}
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved