I am looking for a function in C++ that calculates how many seconds have past from 1/1/1970 until today.
See man mktime
:
#include <time.h>
time_t secsSinceEpoch = mktime(localtime(NULL));
#include <time.h>
time_t seconds_past_epoch = time(0);
Available on most operating systems.
time_t time(void) time_t time(time_t *ptr)
include: time.h
Returns the number of seconds that have passed since midnight, 1st January 1970 GMT (or pm, 31st December 1969 EST). If the parameter is not NULL, the same value is stored in the location pointed to. Follow this link for information on the time_t type. The value returned may be used as a reliable measure of elapsed time, and may be passed to ctime() or conversion into a human-readable string.
Example:
time_t t1=time(NULL);
do_something_long();
time_t t2=time(NULL);
printf("%d seconds elapsed\n", t2-t1);
time_t values are produced from the clock by time. time_t values are produced from y,m,d,h,m,s parts by mktime and timegm. time_t values are analysed into y,m,d,h,m,s by localtime and gmtime. time_t values are converted to readable strings by ctime.