Convert seconds to Days, Minutes and Seconds

后端 未结 4 642
走了就别回头了
走了就别回头了 2021-01-02 09:41

Hey everyone. I\'ve continuing to learn C++ and I\'ve been set the \'challenge\' of converting seconds to format as the Days,Minutes and Seconds.

For example: 316000

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 09:58

    For example: 31600000 = 365 days, 46 minutes, 40 seconds.

    Really?

    $ bc
    365*24*60*60 + 46*60 + 40
    31538800
    
    365*24*60*60 + 1066*60 + 40
    31600000
    

    Did you mean "convert the input into days, hours, minutes and seconds, and then discard the hours" or "convert the input into days, total minutes within a day (i.e. can be more than 60), and seconds"?

    In the second case I think you should replace the instruction for minutes with

    long minutes = input_seconds / secs_to_min % (mins_in_hour * hours_in_day);
    

提交回复
热议问题