[轉]根據時間(NSDate)獲取具體的信息:月份、星期、天等

[iPhone類代碼]計算時間,month,week and day,hour , minutes and second

//initializtion parameter NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *now; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |                                          NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; now=[NSDate date]; comps = [calendar components:unitFlags fromDate:now]; week = [comps weekday];     month = [comps month]; day = [comps day]; hour = [comps hour]; min = [comps minute]; sec = [comps second]; //Week: 1 --星期天 2--星期一 3--星期二 4--星期三 5--星期四 6--星期五 7--星期六
相關文章
相關標籤/搜索