简体   繁体   中英

C++, how do I generate time_t?

istringstream ss ("12/01/2015-05:00:00")
ss.imbue("en_US.utf-8"));
struct tm t_time;
ss >> std::get_time(&t_time, "%d/%m/%Y-%H:%M:%S");
time_t num_time=timelocal(&t_time) 

But I wasn't allow to use boost or get_time .

The purpose is to get time_t

My idea is to manually use sscanf these values onto the struct tm. But the thing is

struct tm {
   int tm_sec;   // seconds of minutes from 0 to 61
   int tm_min;   // minutes of hour from 0 to 59
   int tm_hour;  // hours of day from 0 to 24
   int tm_mday;  // day of month from 1 to 31
   int tm_mon;   // month of year from 0 to 11
   int tm_year;  // year since 1900
   int tm_wday;  // days since sunday
   int tm_yday;  // days since January 1st
   int tm_isdst; // hours of daylight savings time
}

The items from tm_sec to tm_mon is not difficult. But how do I do the the subsequent ones? (such as tm_wday , tm_yday ?

mktime ignores tm_wday and tm_yday . You must know the year. As for tm_isdst , if you don't know it, set to -1 and mktime will attempt to determine it automatically from installed timezone data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM