c++ - 用 C++ 检查日期

标签 c++ date

我想检查当前日期是否是特定的设置日期,如果该日期正确,我希望它运行一个代码块。否则它将结束脚本。 我在想,它看起来像这样吗:

int/string? date = ????;

if(date==10/07/13){
    }
else 
    return 0;

我会有一个名为 date 的变量,它会获取当前日期。 我看到的问题是其中有斜杠。另外,我想补充一点,我是在英文版 Windows 7 计算机上写这篇文章的,我希望它能在荷兰文 Windows 7 计算机上打开。这会成为问题吗?

最佳答案

这应该让你开始:

#include <ctime>
#include <iostream>

int main()
{
    std::time_t tp = std::time(NULL);   // current time, an integer
                                        // counting seconds since epoch

    std::tm * ts = std::localtime(&tp); // parsed into human conventions


    std::cout << "Year: " << 1900 + ts->tm_year << "\n"
              << "Month: " << ts->tm_mon << "\n"
              << "Day: " << ts->tm_mday << "\n"
        ;
}

除了 localtime(使用当前语言环境),您还可以使用 gmtime 来获取 UTC 时间。

关于c++ - 用 C++ 检查日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633997/

相关文章:

php - jQuery fullCalendar dayClick - 将(日期)转换为 mm/dd/yy

mysql - 如何将当前周过滤为日期范围

python - 转换日期Python

c++ - 为什么这个函数模板调用有效?

c++ - 数组打印出错误的数字

c++ - Eclipse、minGW 和 C++11

c++ - 解析空终止字符串的启发式

javascript - 为什么 new Date(dateString) 在具有完全相同输入的不同设备上返回两个不同的日期?

c++ - Eclipse C++ 不允许我使用全局变量?

PHP 使用今天的日期生成一个随机数