本文介绍了将当前日期保存到3 Ints - C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将当前的日,月和年节省成三个整数。我不知道该怎么做。
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;
}
以上链接
-
time(0)
:当前时间:
-
localtime
:
-
struct tm
:
time(0)
: current time:http://cplusplus.com/reference/clibrary/ctime/time/localtime
:http://cplusplus.com/reference/clibrary/ctime/localtime/struct tm
:http://cplusplus.com/reference/clibrary/ctime/tm/
Links from above
这篇关于将当前日期保存到3 Ints - C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!