Преобразовать формат времени в относительное время Цель C - PullRequest
2 голосов
/ 15 мая 2011

Как преобразовать 2011-05-08T22: 08: 38Z в формат относительного времени в Objective C?

1 Ответ

4 голосов
/ 15 мая 2011
// create a date formatter
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
// set the formatter to parse RFC 3339 dates
[formatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
// the formatter parses your date into an NSDate instance
NSDate *date = [formatter dateFromString:@"2011-05-08T22:08:38Z"];

// now to get relative information you can do things like this, which
// will give you the number of seconds since now
NSTimeInterval secondsFromNow = [date timeIntervalSinceNow];

// or this, which will give you the time interval between this data
// and another date
NSTimeInterval secondsFromOther = [date timeIntervalSinceDate:someOtherDateInstance];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...