2009年3月15日日曜日

memo_NSDateから日時・時間を取得する方法


// Assume that (NSDate *)date already exists.

NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int flags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:flags fromDate:date];
[calendar release];

// Here, you can get information about (NSDate *)date
// by using methods year, month, day, hour, minute, and second of instance (NSCalendar *)components.

[components release];


参考:
【Cocoa】NSDateから日時の値を取得する

0 件のコメント: