title: How do I break down an NSTimeInterval into year, months, days, hours, minutes and seconds on iPhone?
body: <p>I have a time interval that spans years and I want all the time components from year down to seconds.</p>
  
  <p>My first thought is to integer divide the time interval by seconds in a year, subtract that from a running total of seconds, divide that by seconds in a month, subtract that from the running total and so on.</p>
  
  <p>That just seems convoluted and I've read that whenever you are doing something that looks convoluted, there is probably a built-in method.</p>
  
  <p>Is there?</p>
  
  <p>I integrated Alex's 2nd method into my code.</p>
  
  <p>It's in a method called by a UIDatePicker in my interface.</p>
  
  <pre><code>NSDate *now = [NSDate date];
  NSDate *then = self.datePicker.date;
  NSTimeInterval howLong = [now timeIntervalSinceDate:then];
  
  NSDate *date = [NSDate dateWithTimeIntervalSince1970:howLong];
  NSString *dateStr = [date description];
  const char *dateStrPtr = [dateStr UTF8String];
  int year, month, day, hour, minute, sec;
  
  sscanf(dateStrPtr, "%d-%d-%d %d:%d:%d", &amp;year, &amp;month, &amp;day, &amp;hour, &amp;minute, &amp;sec);
  year -= 1970;
  
  NSLog(@"%d years\n%d months\n%d days\n%d hours\n%d minutes\n%d seconds", year, month, day, hour, minute, sec);
  </code></pre>
  
  <p>When I set the date picker to a date 1 year and 1 day in the past, I get:</p>
  
  <blockquote>
    <p>1 years 1 months 1 days 16 hours 0
    minutes 20 seconds</p>
  </blockquote>
  
  <p>which is 1 month and 16 hours off. If I set the date picker to 1 day in the past, I am off by the same amount.</p>
  
  <p><strong>Update</strong>: I have an app that calculates your age in years, given your birthday (set from a UIDatePicker), yet it was often off. This proves there was an inaccuracy, but I can't figure out where it comes from, can you?</p>