//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--星期六
记录下,
转载http://www.cocoachina.com/bbs/read.php?tid-3377.html
我实际使用的方法
NSDate * date = [NSDate date]; //设置时间输出格式: NSDateFormatter * df = [[NSDateFormatter alloc] init ]; [df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"]; NSString * na = [df stringFromDate:date];