[ACCEPTED]-find how many seconds past since 1/1/1970-c++

Accepted answer
Score: 25
#include <time.h>

time_t seconds_past_epoch = time(0);

Available on most operating systems.


Score: 5

time_t time(void) time_t time(time_t *ptr)

include: time.h

Returns 15 the number of seconds that have passed since 14 midnight, 1st January 1970 GMT (or pm, 31st 13 December 1969 EST). If the parameter is 12 not NULL, the same value is stored in the 11 location pointed to. Follow this link for 10 information on the time_t type. The value 9 returned may be used as a reliable measure 8 of elapsed time, and may be passed to ctime() or 7 conversion into a human-readable string.


time_t t1=time(NULL);
time_t t2=time(NULL);
printf("%d seconds elapsed\n", t2-t1);

time_t 6 values are produced from the clock by time. time_t 5 values are produced from y,m,d,h,m,s parts 4 by mktime and timegm. time_t values are 3 analysed into y,m,d,h,m,s by localtime and 2 gmtime. time_t values are converted to readable 1 strings by ctime.

Score: 2

See man mktime:

#include <time.h>

time_t secsSinceEpoch = mktime(localtime(NULL));


More Related questions