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

后端 未结 11 2392
[愿得一人]
[愿得一人] 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 01:57

    try this,

    int forHours = seconds / 3600, 
    remainder = seconds % 3600, 
    forMinutes = remainder / 60, 
    forSeconds = remainder % 60;
    

    and you can use it to get more details as days, weeks, months, and years by following the same procedure

提交回复
热议问题