Algorithm to add or subtract days from a date?

后端 未结 10 1188
野的像风
野的像风 2020-12-01 14:10

I\'m trying to write a Date class in an attempt to learn C++.

I\'m trying to find an algorithm to add or subtract days to a date, where Day starts from 1 and Month s

10条回答
  •  -上瘾入骨i
    2020-12-01 14:56

    I would suggest writing first a routine which converts year-month-day into a number of days since fixed date, say, since 1.01.01. And a symmetric routine which would convert it back.

    Don't forget to process leap years correctly!

    Having those two, your task would be trivial.

提交回复
热议问题