C library function -time()

C Standard Library - <time.h>

Description

C Library Functionstime_t time(time_t *seconds)Returns the time elapsed since the Epoch (1970-01-01 00:00:00 UTC) in seconds. IfsecondsIf not empty, the return value is also stored in the variable.secondsIn.

Declaration

Below is the declaration of the time() function.

time_t time(time_t *seconds)

Parameter

  • seconds-- This is a pointer to an object of type time_t, used to store the value of seconds.

Return Value

Returns the current calendar time as a time_t object.

Example

The following example demonstrates the usage of the time() function.

Example

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

Let us compile and run the above program, which will produce the following result:

自 1970-01-01 起的小时数 = 373711

C Standard Library - <time.h>

other extensions