Arithmetics on calendar dates in C or C++ (add N days to given date)

后端 未结 8 1088
误落风尘
误落风尘 2020-12-06 07:47

I have been given a date, Which I am taking as an input like (day, month, year): 12, 03, 87.

Now I need to find out the date after n days.<

8条回答
  •  眼角桃花
    2020-12-06 08:14

    the easiest trick is to use time_t type and corresponding functions.

    mktime will convert tm structure to time_t. which is an integer value counting the seconds starting 01-Jan-1970.

    After you have a time_t value just add the seconds count you need (86400 per day).

    To convert back, use gmtime or localtime

提交回复
热议问题