How to calculate the number of days between two given dates? (Leap year obstacle)

后端 未结 6 1059
情深已故
情深已故 2020-12-11 20:44
  • Any year evenly divisible by 400 is a leap year (e.g., 2000 was a leap year).
  • Any other year evenly divisible by 100 is not a leap year (e.g., 1700, 1800 and
6条回答
  •  误落风尘
    2020-12-11 21:31

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

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

    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).

提交回复
热议问题