使程序检查当前日期是否=预期日期
Make a program check if current date = intended date
有没有办法让 c++ 等到预定的日期,什么时候应该继续处理其余的代码?
我不希望它使用等待或睡眠之类的东西等待,我实际上希望它只是使用 if 语句进行检查。极其糟糕的伪代码示例:
if current_date == intended_date
cout << "Happy Birthday";
end
我希望程序只有在满足生日条件的情况下才说生日快乐。我知道您可以使用 std::chrono::system_clock::now(( 获取当前日期。但是,我不知道如何格式化intended_date以便它可以根据当前日期进行检查。
我认为标准模块chrono和iomanip为您提供了所需的内容:
#include <chrono>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <list>
int main()
{
auto currentTime = std::chrono::system_clock::to_time_t(
std::chrono::system_clock::now()
);
std::stringstream timeStream;
timeStream << std::put_time(std::localtime(¤tTime), "%m-%d");
const std::list<std::string> birthdays = {"12-08", "10-03"};
for (auto& date : birthdays)
{
if(timeStream.str() == date)
{
std::cout << "Happy birthday!!n";
}
else
{
std::cout << "Try another day!!n";
}
}
return 0;
}
相关文章:
- Gtkmm 会不断检查 Gtk::日历上的所选日期是否发生变化
- 使程序检查当前日期是否=预期日期
- 确定夏令时是否适用于特定日期
- 是否有更有效的方法来生成日期的REGEX字符串
- 在拥有C /CX项目时,是否可以设置calendardatePicker的默认日期
- 是否可以在特定日期后没有运行可执行文件
- 如何检查日期格式(日/月/年)是否正确C++
- 在 C++20 中获取当前日期/时间是否线程安全?
- 如何确定给定日期是否为C++的工作日
- 在 CLI 中转换日期时间time_t错误处理C++是否安全
- 像儒略数字用于计算日期一样,是否有任何特定的数字来计算时间
- C++ - 如何检查今天的日期是否为字符串?
- 对于C++中的日期/时间库,是否有一种轻量级的Boost替代方案
- 有没有办法确定日期/时间是否不存在
- 使用UTC来回转换日期以忽略DST但仍使用当前用户的有效区域设置是否安全
- 是否有一个库(跨平台)来处理操作系统日期
- 在 Linux 的 C/C++ 中是否可以在达到指定的日期/时间时收到通知
- DTN_DATETIMECHANGE断点和日期时间选取器控件是否存在问题
- C++检查日期是否有效
- 输出不显示日期是否有效