Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you subtract 12/12/2001 from 05/05/2002 what will be the date? The chronological distance between two dates can't be a date, it's alway some kind of interval. You can use <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html" rel="nofollow noreferrer">timeIntervalSinceDate:</a> to calculate the interval.</p> <p>To localize you can try the following steps:</p> <ul> <li><p>You can use the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html" rel="nofollow noreferrer">NSCalendar</a> with dateFromComponents: passing in a <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html" rel="nofollow noreferrer">NSDateComponents</a>. </p></li> <li><p>To break down a timeInterval into <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html" rel="nofollow noreferrer">NSDateComponents</a> look at <a href="https://stackoverflow.com/questions/1237778/how-do-i-break-down-an-nstimeinterval-into-year-months-days-hours-minutes-and">How do I break down an NSTimeInterval into year, months, days, hours, minutes and seconds on iPhone?</a>.</p></li> <li><p>Finally use the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html" rel="nofollow noreferrer">NSDateFormatter</a> and <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html#//apple_ref/doc/uid/20000447-BCIGICCF" rel="nofollow noreferrer">initWithDateFormat:allowNaturalLanguage:</a> to get your localized string. The <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/Articles/df100103.html#//apple_ref/doc/uid/TP40007972-SW9" rel="nofollow noreferrer">Date Format String Syntax</a> shows the different placeholders. </p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload