title: how to calculate difference between two times in different dates in iOS?
body: <p>starttime= 23:00 pm
  end time= 5:00 am</p>
  
  <p>I need the summing time of the start time to end time 
  i am trying this code but it is not helpful to me </p>
  
  <pre><code>NSDateFormatter *formatter = [NSDateFormatter new];
          [formatter setDateFormat:@"HH"];
  
          NSDate *currentTime = [NSDate date];
          NSDate *openTime = [formatter dateFromString:start];
          NSDate *closeTime = [formatter dateFromString:end ];
          NSCalendar *calender = [NSCalendar currentCalendar];
          NSDateComponents *currentTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:currentTime];
          NSDateComponents *openTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:openTime];
          NSDateComponents *closeTimeComponents = [calender components:NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:closeTime];
  
          NSUInteger currentTimeSeconds = currentTimeComponents.hour;
  
          NSUInteger openTimeSeconds = openTimeComponents.hour;
  
          NSUInteger closeTimeSeconds = closeTimeComponents.hour;
  
          if (currentTimeSeconds&gt;openTimeSeconds &amp;&amp; currentTimeSeconds&lt;closeTimeSeconds) {
              NSLog(@"Time Between Open and Close Time %lu",(unsigned long)currentTimeSeconds);
          }
  </code></pre>
  
  <p>and it shows 0 hors.
  please help me some one?
  thanks in advance</p>