11

Possible Duplicate:
How to calculate time in hours between two dates in iOS

I am beginner to Objective-C, so I need your help in syntax making.

My problem goes like this:

I have 2 Strings, and I want to convert that into NSDate and then calculate the time difference between the dates in minutes.

How can I do this?

3

1 Answer 1

35
  1. Use NSDateFormatter to convert the date strings into NSDate objects.
  2. Call -[NSDate timeIntervalSinceDate:] to get the difference between the two dates in seconds.
  3. Divide by 60 to get the difference in minutes.

Alternatively, you can use NSCalendar and NSDateComponents to calculate the difference in minutes for different calendars by using the components:fromDate:toDate:options: method.

Sign up to request clarification or add additional context in comments.

1 Comment

Here you go - (NSInteger)minutesBetween:(NSDate *)firstDate and:(NSDate *)secondDate { NSTimeInterval interval = [secondDate timeIntervalSinceDate:firstDate]; return (int)interval / 60; }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.