Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - time()

C Library Function - time()

C Standard Library - <time.h> C Standard Library -

Description

C library function *time_t time(time_t seconds) returns the time elapsed since the Epoch (1970-01-01 00:00:00 UTC), in seconds. If seconds is not null, the return value is also stored in the variable seconds it.

Declaration

Below is the declaration of the time() function.



time_t time(time_t *seconds)

Parameters

Return Value

Returns the current calendar time as a time_t object.

Example

The following example demonstrates the use 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's compile and run the above program, which will produce the following result:



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

C Standard Library - <time.h> C Standard Library -