NSTimeInterval to NSDate

后端 未结 7 1489
逝去的感伤
逝去的感伤 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:17

    Via apple developers:

    //1408709486 - time interval value

    NSDate *lastUpdate = [[NSDate alloc] initWithTimeIntervalSince1970:1408709486];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    
    NSLog(@"date time: %@", [dateFormatter stringFromDate:lastUpdate]);
    

    You will get: date time: Aug 22, 2014, 3:11:26 PM

提交回复
热议问题