Reputation: 111
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
.
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
?
Upvotes: 0
Views: 212
Reputation: 120239
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.
Upvotes: 1