2

I have two dates like startDate = 2016-02-24 10:25:11 +0000 and endDate = 2016-02-24 10:26:11 +0000.

I want to find time interval between these dates in seconds.

Thanks in advance.

1
  • i have tried this but it is giving me wrong calculation. When i made difference of 10 minutes between dates. It is giving me result of 5. I have tried this code - NSTimeInterval distanceBetweenDates = [sDate timeIntervalSinceDate:eDate]; double secondsInAnHour = 3600; NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour; Commented Feb 24, 2016 at 5:10

1 Answer 1

3

Hope this can help you.

NSString *startDate = @"2016-02-24 10:25:11 +0000"; NSString *endDate = @"2016-02-24 10:26:11 +0000"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; NSDate *start = [formatter dateFromString:startDate]; NSDate *end = [formatter dateFromString:endDate]; NSTimeInterval interval = [end timeIntervalSinceDate:start]; NSLog(@"time interval:%f", interval); 
Sign up to request clarification or add additional context in comments.

1 Comment

Output: time interval:60.000000

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.