c++ - Converting integer to time format -


i looking nice way convert int time format. example, take in integer 460 , returns 5:00, or integer 1432 , returns 14:32. way think of tediously turning string, breaking 2 strings, , checking both strings correctness.

thank you.

as pointed out in comment, think representation highly problematic. propose represent seconds, , use simple calculations parsing minutes/hours.

class playtime {     size_t sec;    public:     playtime(size_t hours = 0, size_t minutes = 0, size_t seconds = 0)       : sec(hours*60*60 + minutes*60 + seconds) {}      size_t hours() const { return sec/(60*60); }     size_t minutes() const { return (sec/60)%60; }     size_t seconds() const { return sec%60; }      playtime & operator +=(const playtime &that) {         this-> sec += that.sec;         return *this;     } };  playtime operator+(playtime a, playtime b) { return a+=b; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -