The time() function is defined in the time.h (ctime in c) header file. This function returns the time in seconds since January 1, 1970 00:00:00 UTC (Unix timestamp). If second is not a null pointer, the returned value is also stored in the object pointed to by second.
Syntax:
time_t time( time_t *second )
Parameters: This function accepts a single parameter second. This parameter is used to set the time_t object that stores the time.
Return value: This function returns the current calendar time as an object of type time_t.
Example 1:
#include <stdio.h> #include <time.h> int main () { time_t seconds; seconds = time(NULL); printf("Seconds since January 1, 1970 = %ld\n", seconds); return(0); }
Output:
Seconds since January 1, 1970 = 1538123990
Example 2:
#include <stdio.h> #include <time.h> int main() { time_t seconds; // 存储时间秒 time(&seconds); printf("Seconds since January 1, 1970 = %ld\n", seconds); return 0; }
Output:
Seconds since January 1, 1970 = 1538123990
Related recommendations: "C Tutorial"
This article is an introduction to the use of the time() function in C. I hope it will help Friends in need help!
The above is the detailed content of How to use the time() function in C?. For more information, please follow other related articles on the PHP Chinese website!