【发布时间】:2015-10-22 14:04:02
【问题描述】:
我试过这样做:
struct Den_t
{
int day, month, year;
};
int main()
{
struct Den_t* Datum = new struct Den_t;
struct Den_t* Dnes = new struct Den_t;
time_t theTime = time(NULL);
struct tm aTime;
localtime_s(&aTime, &theTime);
Dnes->day = aTime.tm_mday;
Dnes->month = aTime.tm_mon + 1;
Dnes->year = aTime.tm_yday + 1900;
cin >> Datum->day >> Datum->month >> Datum->year;
if (Dnes->year - Datum->year >= 18 )
cout << "full aged " << endl;
else
cout << "not full aged " << endl;
system("PAUSE");
return 0;
}
但我不知何故无法理解我什至应该比较和减少什么,谁能解释一下
我还需要做什么来告诉人们的日期,例如在 float by 比较用户输入的实际时间和日期的年月日 程序?
【问题讨论】:
-
不要实现你自己的日期时间函数(除非是学校作业或类似的),而是使用functionality in the standard library。
-
你有一个好的开始,但如果你想知道一个人的确切年龄,你还必须考虑出生日期。例如,假设 18 岁的孩子出生于 1 月 1 日或 12 月 31 日,这很重要。
-
@BoPersson 这正是我所做的,我使用 cin 将日期输入为“日月年”(每个空格分开)但我现在不知道如何继续
标签: c++ datetime time date-difference