Convert seconds to Days, Minutes and Seconds

后端 未结 4 633
走了就别回头了
走了就别回头了 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 10:00

    One of the things about programming is that there is never just one way to do something. In fact if I were to set my mind to it, I might be able to come up with a dozen completely different ways to accomplish this. You're not missing anything if your code meets requirements.

    For your amusement, here's a way to format up hours:minutes:seconds under Windows (elapsed is a double & represents number of seconds elapsed since... something)

    sprintf_s(buf, "%01.0f:%02.0f:%02.2f", floor(elapsed/3600.0), floor(fmod(elapsed,3600.0)/60.0), fmod(elapsed,60.0));
    

提交回复
热议问题