C examples for time.h:time
function
<ctime> <time.h>
Get current time
time_t time (time_t* timer);
Parameter | Description |
---|---|
timer | Pointer to an object of type time_t. |
The current calendar time as a time_t object.
On error, it returns a value of -1.
#include <stdio.h> #include <time.h> int main ()/*from w w w.j a va2 s . c o m*/ { time_t timer; struct tm year2020 = {0}; double seconds; year2020.tm_hour = 0; year2020.tm_min = 0; year2020.tm_sec = 0; year2020.tm_year = 120; year2020.tm_mon = 0; year2020.tm_mday = 1; time(&timer); /* get current time; same as: timer = time(NULL) */ seconds = difftime(timer,mktime(&year2020)); printf ("%.f seconds since January 1, 2000 in the current timezone", seconds); return 0; }