Determining the difference between dates

后端 未结 8 1870
無奈伤痛
無奈伤痛 2020-12-10 04:34

I\'m trying to figure out a way for my program to take a date (like February 2nd, 2003) and show the difference between the two with another date (like April 2nd, 2012), exc

8条回答
  •  独厮守ぢ
    2020-12-10 05:14

    I'm not sure what platform are you on? Windows, Linux? But let us pretend that you would like to have a platform independent solution and the langugage is standard C++.

    If you can use libraries you can use the Boost::Date_Time library (http://www.boost.org/doc/libs/1_49_0/doc/html/date_time.html)

    If you cannot use libraries to solve your assignment, you will need to find a common simple ground. Maybe you could convert all the dates to seconds, or days substract them and then convert that back to the data again. Substracting days or months as integers will not help as it will lead to incorrect results unless you do not take into account the rest. Hope that helps.

    Like dbrank0 pointed it out. :)

提交回复
热议问题