2011-02-11 145 views

回答

3

可以初始化並使用公曆,如:

NSDateComponents *comps = [[NSDateComponents alloc] init]; 
    [comps setYear:1965]; 
    [comps setMonth:1]; 
    [comps setDay:6]; 
    [comps setHour:14]; 
    [comps setMinute:10]; 
    [comps setSecond:0]; 
    NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    NSDate *date = [gregorianCalendar dateFromComponents:comps]; 

和當前日曆中:

NSDateComponents *comps = [[NSDateComponents alloc] init]; 
    [comps setYear:1965]; 
    [comps setMonth:1]; 
    [comps setDay:6]; 
    [comps setHour:14]; 
    [comps setMinute:10]; 
    [comps setSecond:0]; 
    NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];