How to convert a time into epoch time?

Use the mktime(3) function. For example:

struct tm t = {0};  // Initalize to all 0's
t.tm_year = 112;  // This is year-1900, so 112 = 2012
t.tm_mon = 8;
t.tm_mday = 15;
t.tm_hour = 21;
t.tm_min = 54;
t.tm_sec = 13;
time_t timeSinceEpoch = mktime(&t);
// Result: 1347764053

Leave a Comment