This question already has answers here:
How to get current time and date in C++?
                                
                                    (23个答案)
                                
                        
                                5年前关闭。
            
                    
我想编写一个C ++代码来检查该人是否超过18岁,但不是通过询问年龄而是通过该人的DOB。有什么方法可以帮助我从系统获取当前日期?

最佳答案

#include <iostream>
#include <ctime>

void printTime() {
    time_t t = time(0);
    struct tm * timeStruct = localtime(&t);
    std::cout << (timeStruct->tm_year) << '-' << (timeStruct->tm_mon) << '-'<<  (timeStruct->tm_mday) << std::endl;
}

09-05 07:17