1
如何計算兩個日期之間的日期。日期ar保存在整數變量(數組)中。如果有一些功能會很好。如果否,我嘗試使用for循環,但沒有找到正確的算法。C++中兩個日期的區別
#include <iostream>
int stoi(std::string s);
int main(){
/* 5th november of 2013 */
int days1[0] = 05;
int days1[1] = 11;
int days1[2] = 2013;
/* 7th october of 2016 */
int days2[0] = 07;
int days2[1] = 10;
int days2[2] = 2016;
int days = date(days1,days2);
std::cout << days << std::endl;
return 0;
}
int date(int dates1[], int date2[]){
int days = 0;
/* Task: how much days is past */
/* Days in each month must be real (31 or 30 or 29/28) */
/* there can't be constant as 31 days on each month or 365 days in year */
return days;
}
計算時間,因爲例如起始日期以秒爲01.01.1970到當前的日期。用這兩個日期做這個。然後減去兩者,然後計算結果爲分鐘/小時/天或月份。 – user743414
你可以使用std :: chrono :: duration –
使用Boost。它有一個日期時間處理模塊。 –