Вопрос

When tracking time since a date using NSTimeInterval, it shows 0.000000 in the NSLog. Here is my Time Interval:

NSTimeInterval timeInterval = [intialtime timeIntervalSinceNow];

Here is how I log the data:

NSLog(@"%f",timeInterval);

What am I missing? Also, I want the time interval to show minutes since the date. Would I need to change anything to make this happen?

Это было полезно?

Решение

Panic, try this.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.timeStyle = NSDateFormatterNoStyle;
formatter.dateFormat = @"MM/dd/yyyy";

NSDate *intialTime= [formatter dateFromString:@"12/11/2005"];

NSDate *presentDate = [NSDate date];

NSTimeInterval timeInterval = [presentDate timeIntervalSinceDate:intialTime];

int seconds = (int)ceil(timeInterval);
int mins = seconds / 60;

NSLog(@"Time interval in Mins:%d",mins);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top