1. 程式人生 > >iOS 獲取 年 月 日

iOS 獲取 年 月 日

    NSDate *  timeDate=[NSDate date];
    NSCalendar  * cal=[NSCalendar currentCalendar];
    NSUInteger  unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
    NSDateComponents * conponent= [cal components:unitFlags fromDate:timeDate];
    NSInteger year=[conponent year];
    NSInteger month=[conponent month];
    NSInteger day=[conponent day];