C/C++ - 检查今天是否是本月的第一个星期一

use*_*262 0 c c++ calendar date

如何使用 C/C++ 代码检查今天是否是本月的第一个星期一?

使用 Java 和 C# 更简单(如下面的链接所示)。

任何人都可以帮助我使用 C/C++ 实现这一目标。

c-sharp-how-can-i-check-if-today-is-the-the-the-the-monday-of-the-month

java检查日期是否是本月的第一个星期日

Ste*_*sca 5

这应该是你要找的:

#include <iostream>
#include <ctime>

int main(){
   std::time_t result = std::time(NULL);
   const std::tm* t =  std::localtime(&result);
   if(t->tm_wday == 1 and t->tm_mday <= 7)
    std::cout << "true" << std::endl;
    else
    std::cout << "false" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

代码已经在这里测试。