NSNumber of seconds to Hours, minutes, seconds

前端 未结 4 1054
情深已故
情深已故 2020-12-06 07:47

I am having a terrible time trying to do something that should be easy. I have a NSNumber value of 32025.89 seconds. I need to represent that in Hours, Minutes, Seconds. Is

4条回答
  •  鱼传尺愫
    2020-12-06 08:12

    Here's a way without any libraries except for modf() from math.h:

    float fsec = 32025.89f, frac = 0;
    int milliseconds = (int)(modf(fsec, &frac) * 1000);
    int isec = (int)frac;
    int hours = isec / 3600;
    int minutes = (isec % 3600) / 60;
    int seconds = isec % 60;
    

提交回复
热议问题