time - get time in seconds
#include <time.h>
long time(NULL);
Think of this function as returning a long
as output and as taking only NULL
as input.
This function gets the current date and time as seconds since January 1, 1970, 00:00:00 UTC, otherwise known as the Epoch.
time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
If tloc
is non-NULL, the return value is also stored in the memory pointed to by tloc
.
This function returns the number of seconds since January 1, 1970, 00:00:00 UTC.
On success, the value of time in seconds since the Epoch is returned. On error, ((time_t) -1)
is returned, and errno
is set appropriately.
#include <stdio.h>
#include <time.h>
int main(void)
{
printf("The time is now %li.\n", time(NULL));
}