Showing posts with label NSDate dateWithTimeIntervalSinceReferenceDate example. Show all posts
Showing posts with label NSDate dateWithTimeIntervalSinceReferenceDate example. Show all posts

Monday, May 23, 2011

NSDate dateWithTimeIntervalSinceReferenceDate example objc

NSDate dateWithTimeIntervalSinceReferenceDate method returns an NSDate object initialized relative the first instant of 1 January 2001, GMT by a given number of seconds. In most cases, NSDate dateWithTimeIntervalSinceReferenceDate is not preferred since you must know how many seconds relative to the GMT 2001/01/01.

Example code>

[NSDate dateWithTimeIntervalSinceReferenceDate Example qouted from Apple Developer Site]
 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"];

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000];

NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"formattedDateString: %@", formattedDateString);
// For US English, the output may be:
// formattedDateString: 2001-01-02 at 13:00