I'm developing a C++ application which is run on linux. I need to calculate epoch time for a given date and vice versa. (no of seconds elapsed since 1979-01-01) I used the following two methods.I need to convert the given date to epoch time and again convert that epoch time to the corresponding date.But the following methods doesn't give me the correct answer.
Method to calculate the epoch time:
time_t HistoryCache::ConvertTimeToEpoc(const char* _zTime,const char* _zFormat)
struct tm tmTime;
time_t tTime = mktime(&tmTime);
Method to find the corresponding date for a given time in seconds:
const char* HistoryCache::GetTimeStamp(float epochStr)
static char timestamp = "";
time_t tt = 0;
memset(timestamp, '\0', 64);
tt = epochStr;
strftime(timestamp, 64, "%Y-%m-%d:%H:%M:%S", localtime(&tt));
In my main method I'm doing something like below.
time_t timeFrom = ConvertTimeToEpoc("2010-01-05:000000","%Y-%m-%d:%H:%M:%S");
long lTime = (long)timeFrom;
const char* dateString = GetTimeStamp(1262649600)
My problem is this. Lets think that the value I get as epoch time for the 2010-01-05:000000 is 1262649600. (lTime value) Then I use the same value (1262649600) as a input to the GetTimeStamp method, I didnt get the dateString as 2010-01-05:000000. The date is changed by one day. Can some one please help me on this and it would be really helpful.