how to convert datetime to unix timestamp in c?

You could try a combination of strptime and mktime

struct tm tm;
time_t epoch;
if ( strptime(timestamp, "%Y-%m-%d %H:%M:%S", &tm) != NULL )
  epoch = mktime(&tm);
else
  // badness

Leave a Comment