NSTimeInterval to HH:mm:ss?

后端 未结 12 1770
陌清茗
陌清茗 2020-12-04 08:53

If I have an NSTimeInterval that is set to say 200.0, is there a way to convert that into 00:03:20, I was thinking I could initialise an NSDate with it and then use NSDateFo

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 09:36

    NSTimeInterval ti = 3667;
    double hours = floor(ti / 60 / 60);
    double minutes = floor((ti - (hours * 60 * 60)) / 60);
    double seconds = floor(ti - (hours * 60 * 60) - (minutes * 60));
    

提交回复
热议问题