计算两天之间相差天数最简单的代码

//Rata Die day one is 0001-01-01 
int calculateDays(uint32_t year, uint32_t month, uint32_t day) {
   if (month < 3)
      year--, month += 12;
   return 365 * year + year / 4 - year / 100 + year / 400 + (153 * month - 457) / 5 + day - 306;
}


int diffDays=calculateDays(2019, 8, 1) - calculateDays(1970, 1, 1);

std::cout<<diffDays<<std::endl;
posted @ 2020-05-12 12:01  多弗朗强哥  阅读(224)  评论(0编辑  收藏  举报