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

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

    Use the built-in function strftime():

    static char timestr[80];
    char * HHMMSS ( time_t secs )
    {
        struct tm ts;
        ts = *localtime(&secs);
        strftime(timestr, sizeof(timestr), "%a %b %d %H:%M:%S %Y %Z", &ts); // "Mon May 1, 2012 hh:mm:ss zzz"
        return timestr;
    }
    

提交回复
热议问题