Convert seconds to days, minutes, and hours in Obj-c

后端 未结 11 2378
[愿得一人]
[愿得一人] 2020-12-13 01:16

In objective-c, how can I convert an integer (representing seconds) to days, minutes, an hours?

Thanks!

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 02:02

    Just a bit modification for both compatible with 32 bit & 64 bit. Using NSIntegerthe system will automatically convert to int or long basing on 32/64 bit.

    NSInteger seconds = 10000;
    NSInteger remainder = seconds % 3600;
    NSInteger hours = seconds / 3600;
    NSInteger minutes = remainder / 60;
    NSInteger forSeconds = remainder % 60;
    

    By the same way you can convert to days, weeks, months, years

提交回复
热议问题