Ada*_*eld 26
使用该mktime(3)
功能.例如:
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
Run Code Online (Sandbox Code Playgroud)
小智 5
在Linux上,使用timegm避免减去本地时区:
struct tm tm;
// set tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min and tm.tm_sec
tm.tm_year -= 1900; // year start at 1900
tm.tm_mon--; // months start at january
TIME_STAMP t = timegm(&tm);
Run Code Online (Sandbox Code Playgroud)