代码:
#include <ctime> #include <iostream> int main() { time_t now; struct tm *ts; char yearchar[80]; now = time(NULL); ts = localtime(&now); //ts->tm_mday--; //ts->tm_mday--; //ts->tm_mday--; std::time_t time_temp = mktime(ts); /* Normalise ts */ const std::tm * time_out = std::localtime(&time_temp); strftime(yearchar, sizeof(yearchar), "%Y%m%d", ts); //Sunday == 0, Monday == 1, and so on ... std::cout << "yearchar = "<< yearchar << ", Today is this day of the week: " << time_out->tm_wday << "\n"; std::cout << "(Sunday is 0, Monday is 1, and so on...)\n"; return 0; }
结果:
yearchar = 20171030, Today is this day of the week: 1 (Sunday is 0, Monday is 1, and so on...)
如下图:
来源于:c++ day of week for given date
文章的脚注信息由WordPress的wp-posturl插件自动生成