将当前日期保存到3 Ints - C ++ [英] Save Current Date into 3 Ints - C++

查看:103
本文介绍了将当前日期保存到3 Ints - C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将当前日,月和年保存为三个int。我不知道该怎么做。

I would like to save the current day, month, and year into three ints. I have no idea how to do this.

int day;
int month;
int year;


推荐答案

#include <ctime>

int main() {
    time_t t = time(0);  // current time: http://cplusplus.com/reference/clibrary/ctime/time/
    struct tm * now = localtime(&t);  // http://cplusplus.com/reference/clibrary/ctime/localtime/

    // struct tm: http://cplusplus.com/reference/clibrary/ctime/tm/
    int day = now->tm_mday;
    int month = now->tm_mon + 1;
    int year = now->tm_year + 1900;
}



上面的链接



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆