title: Getting the difference between two Dates (months/days/hours/minutes/seconds) in Swift
body: <p>I am trying to get the difference between the current date as <code>NSDate()</code> and a date from a PHP <code>time();</code> call for example: <code>NSDate(timeIntervalSinceReferenceDate: 1417147270)</code>. How do I go about getting the difference in time between the two dates. I'd like to have a function that compares the two dates and <code>if(seconds &gt; 60)</code> then it returns minutes, <code>if(minutes &gt; 60)</code> return hours and <code>if(hours &gt; 24)</code> return days and so on. </p>
  
  <p>How should I go about this?</p>
  
  <p>EDIT: The current accepted answer has done exactly what I've wanted to do. I recommend it for easy usage for getting the time between two dates in the form that that PHP <code>time()</code> function uses. If you aren't particularly familiar with PHP, that's the time in seconds from January 1st, 1970. This is beneficial for a backend in PHP. If perhaps you're using a backend like NodeJS you might want to consider some of the other options you'll find below.</p>