【发布时间】:2019-04-01 04:52:16
【问题描述】:
我有一个关于在 C++ 中管理日期和时间的问题。我的程序中有两个班飞机和飞行。
我的飞机将包含以下数据:
string tailNumber;//Plane's unique trait
vector<vector<string>> planeSchedule;//2D string vector to contain plane's depature date and arrival date
我的 Flight 类将包含以下数据:
string tailNumber;//Plane's unique trait
string departureDate;
string arrivalDate;
在我的主课中,我将输入离开日期和到达日期的值,格式为:“YYYY/MM/DD HH:MM”,例如:"2019/04/15 10:30" and "2019/04/16 9:30"(我将使用 24 小时格式,时间为 GMT )。
我的问题是如何将上面的两个字符串转换为适当的格式以存储在我的 planeSchedule 中,这样我就可以避免 planeSchedule 中的时间冲突。
例如,如果我下次添加航班,其出发和到达日期介于:2019/04/15 10:30" and "2019/04/16 9:30" 之间,例如:"2019/04/15 13:30" and "2019/04/16 7:30",我将收到类似“航班冲突,飞机无法搭乘航班”的错误。”
我的教授建议使用 unsigned long int 来存储时间,但我真的不知道从哪里开始解决这个问题。任何帮助/建议表示赞赏。
【问题讨论】:
-
时间通常存储为一个整数,表示从纪元开始的单位数(秒、毫秒、100 纳秒等)。见en.wikipedia.org/wiki/Unix_time#Encoding_time_as_a_number
标签: c++