NSTimeInterval to NSDate

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

    0 讨论(0)
提交回复
热议问题