< c‎ | chrono
Defined in header <time.h>
time_t time( time_t *time );

Returns the current calendar time encoded as a time_t object.


[edit] Parameters

time - pointer to a time_t object to store the time in or NULL

[edit] Return value

Current calendar time encoded as time_t object on success, (time_t)(-1) on error. If the argument is not a null pointer, the return value is equal to the value stored in the object pointed to by the argument.

[edit] Notes

The encoding of calendar time in time_t is unspecified, but most systems conform to POSIX specification and return a value of integral type holding the number of seconds since the Epoch. Implementations in which time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038.

[edit] Example

#include <stdio.h>
#include <time.h>
#include <inttypes.h>
int main(void)
    time_t result = time(NULL);
    if(result != -1)
        printf("The current time is %s"
               "(%"PRIuMAX" seconds since the Epoch)\n",
               asctime(gmtime(&result)), (uintmax_t)result);

Possible output:

The current time is Fri Feb 20 16:09:51 2015
(1424448591 seconds since the Epoch)

[edit] References

  • C11 standard (ISO/IEC 9899:2011):
  • The time function (p: 391)
  • C99 standard (ISO/IEC 9899:1999):
  • The time function (p: 341)
  • C89/C90 standard (ISO/IEC 9899:1990):

[edit] See also

converts time since epoch to calendar time expressed as local time
(function) [edit]
converts time since epoch to calendar time expressed as Coordinated Universal Time (UTC)
(function) [edit]
(since C11)
returns the calendar time based on a given time base
(function) [edit]