如何计算两个给定日期之间的天数? (闰年障碍) [英] How to calculate the number of days between two given dates? (Leap year obstacle)

查看:200
本文介绍了如何计算两个给定日期之间的天数? (闰年障碍)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 在任何一年400整除的是闰年(例如,2000年是闰年)。
  • 在任何一年100整除是不是闰年(例如,1700年,1800年和1900年并没有闰年)。
  • 在其他年份能被4整除的是闰年(例如,1996年和2004年是闰年)。

不过,我不知道如何使嵌套的,如果在我的C程序规定,将产生正确的答案...

But I'm not sure how to make nested if states in my c-program that would produce the right answer...

推荐答案

转换他们两个UNIX纪元时间,减去的差异。

Convert them both to UNIX epoch time and subtract the difference.

UNIX的历元时间是几秒钟的自1的日期的总数1970年1月00:00:00.0

UNIX Epoch time is the total number of seconds for a date since 1 January 1970 00:00:00.0

一旦你得到了多少秒,你把这种差异通过的秒数一天(即 24小时*60分钟* 60秒=86400秒的)。

Once you've got the number of seconds, you divide that difference by the number of seconds in a day (which is 24 hours * 60 minutes * 60 seconds = 86400 seconds).

这篇关于如何计算两个给定日期之间的天数? (闰年障碍)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆