Tag: Objective-C/日付と時刻
[NSDate date]]
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setTimeStyle:NSDateFormatterFullStyle]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZ"]; NSDate *date = [formatter dateFromString:@"2009-12-05T20:26:00+09:00"];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] initWithDateFormat:@"%Y/%m/%d %H:%M:%S" allowNaturalLanguage:FALSE] autorelease]; NSDate* date = [NSDate date]; NSString* dateStr = [formatter stringFromDate:date];
NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; [inputDateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; NSDate *dateA = [inputDateFormatter dateFromString:@"2000/03/01 00:00:00"]; NSDate *dateB = [inputDateFormatter dateFromString:@"2000/03/03 00:00:00"]; // dateBとdateAの時間の間隔を取得(dateB - dateAなイメージ) NSTimeInterval since = [dateB timeIntervalSinceDate:dateA]; NSLog(@"%f秒", since); NSLog(@"%f分", since/60); NSLog(@"%f時", since/(60*60)); NSLog(@"%f日", since/(24*60*60)); [inputDateFormatter release];