I have date strings like this:
"2015-11-27"
and from them I want to determine the day of week.
This (live sample) is how I would do it using <ctime>
:
int dayOfWeek(std::string date){
int y, m, d; char c;
std::stringstream(date) >> y >> c >> m >> c >> d;
std::tm t = {0,0,0,d,m-1,y-1900};
std::mktime(&t);
return t.tm_wday;
}
but I'm wondering whether there is a more canonical way to go about this in C++11?