代码:
#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插件自动生成
微信扫一扫,打赏作者吧~![[整理][转载]win下网卡抓包发包库Npcap使用](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2023/08/demo_1-1024x711.jpg&w=280&h=210&zc=1)
![[转载]基础数据char,int,double,string是线程安全的吗?](http://www.jyguagua.com/wp-content/themes/begin/img/random/12.jpg)
![[已解决]nc命令报错 close: Bad file descriptor](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2022/03/Snipaste_2022-03-18_20-16-48.png&w=280&h=210&zc=1)
![[整理]用c++编写的RDTSC性能计时器](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/12/rdtsc-assembly-example.jpg&w=280&h=210&zc=1)