Convert a given date to epoch time and vice versa.
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: Code:
time_t HistoryCache::ConvertTimeToEpoc(const char* _zTime,const char* _zFormat) Method to find the corresponding date for a given time in seconds: Code:
const char* HistoryCache::GetTimeStamp(float epochStr) Code:
time_t timeFrom = ConvertTimeToEpoc("2010-01-05:000000","%Y-%m-%d:%H:%M:%S"); Thank you. |
The following code, which is based on yours, works as expected.
Code:
#include <iostream> |
Thanks a lot and your answer is perfect. It works well.
|
All times are GMT -5. The time now is 11:00 AM. |