NSTimeInterval to NSDate

后端 未结 7 1511
逝去的感伤
逝去的感伤 2020-12-01 16:18

How can I convert a NSTimeInterval to NSDate? Think of it like a stopwatch. I want the initial date to be 00:00:00, and I have a NSTimeInterv

7条回答
  •  时光说笑
    2020-12-01 17:05

    As Josh answer detailed the correct way, if you still want the interval to be in the NSDate format you can use the following method

    + (NSDate *) dateForHour:(int) hour andMinute: (int) minute{
         NSDateComponents * components = [NSDateComponents new];
         components.hour = hour;
        components.minute = minute;
        NSDate * retDate = [[NSCalendar currentCalendar] dateFromComponents:components];
    return retDate;}
    

提交回复
热议问题