I want to convert a given time into epoch(time_t) and vice versa. can anyone tell what is the routine or algorithm for this?
Thanks
Update
epoch_strt.tm_sec = 0;
epoch_strt.tm_min = 0;
epoch_strt.tm_hour = 0;
epoch_strt.tm_mday = 1;
epoch_strt.tm_mon = 1;
epoch_strt.tm_year = 70;
epoch_strt.tm_isdst = -1;
double nsecs = difftime(curtime, basetime);//current time from system, I converrting it to struct tm
but this always return 32399 for some reason.
You should cast it to a long int
instead of int
.
long int t = static_cast<long int> (time(NULL));
An int
might not be enough to hold the time, for example, on my platform, time_t
is a typedef
of __int64
.