Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With only <code>NSString</code>, <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html" rel="nofollow">NSDateFormatter</a> is used to get <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html" rel="nofollow">NSDate</a></p> <pre><code>NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [rfc3339DateFormatter setLocale:enUSPOSIXLocale]; [rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; [rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; // Convert the RFC 3339 date time string to an NSDate. NSDate *date = [rfc3339DateFormatter dateFromString:rfc3339DateTimeString]; </code></pre> <p>If you had separate values for hours, minutes and seconds you could use <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html" rel="nofollow">NSCalendar</a></p> <pre><code>NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setYear:1965]; [comps setMonth:1]; [comps setDay:6]; [comps setHour:14]; [comps setMinute:10]; [comps setSecond:0]; NSDate *date = [gregorian dateFromComponents:comps]; [comps release]; </code></pre> <p>And a perfect solution would be to use timestamps instead of NSString. Not only it's easy to convert timestamps to <code>NSDate</code> (<code>NSDate +dateWithTimeIntervalSinceReferenceDate</code>)and then to <code>NSString</code> when needed, but you can also get the time difference by subtraction.</p> <p>And with two <code>NSDate</code> objects the time difference is calculated with <code>NSDate -timeIntervalSinceDate</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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