-1

タイムスタンプの日付と時刻(形式-2012-06-14T13:15:21Z)を変換して、「1時間前」/「2日前」/「2秒前」などの画面に表示する方法を見つけようとしています。誰かがこれを手伝ってくれますか?

4

1 に答える 1

2

これを試して:

NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDate *date1 = yourDate;
NSDate *date2 = [NSDate date];//Current Date
unsigned int unitFlags = NSDayCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;                   
NSDateComponents *diffComps = [cal components:unitFlags fromDate:date2 toDate:date1 options:0];
[diffComps month] //gives you month
[diffComps day] //gives you day
[diffComps year] // gives you year
[cal release];
于 2012-06-18T05:53:42.600 に答える