C Library Function - time()
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
- 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 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 -