What is time_t in C?

The time_t function returns the time since 00:00:00 UTC, January 1, 1970 (Unix timestamp) in seconds. The time.h header file needs to be included to use this function, as shown below:

#include <time.h>

Prototype

time_t time( time_t *second )

If the variable second is not a NULL pointer, the return value of this function is also stored in the second variable.

Parameters

The time_t function takes a single argument. This is a pointer to an object of type time_t. The value of seconds is stored in this object.

Return value

The return value for this function is the current calendar time as an object time_t type.

Example

The following code shows the use of the time_t function:

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

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved