- int main (int argc, const charchar * argv[])
- {
- @autoreleasepool {
- // // insert code here...
- NSLog(@"Hello, World!");
- NSDate * date = [NSDate date];
- NSLog(@"NSDATA: %@", date);
- //NSdate的数据提取出来
- NSDate *now = [NSDate date];
- NSCalendar *cal = [NSCalendar currentCalendar];
- unsigned int unitFlags = NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSYearCalendarUnit;
- NSDateComponents *dd = [cal components:unitFlags fromDate:now];
- NSInteger week = [dd weekday];
- NSInteger hour = [dd hour];
- NSInteger minute = [dd minute];
- NSInteger year = [dd year];
- NSLog(@"week = %ld",week);
- NSLog(@"hour = %ld",hour);
- NSLog(@"minute = %ld",minute);
- NSLog(@"year = %ld",year);
- // NSCalendarDate * date2 = [NSCalendarDate date];
- // NSInteger year = [date2 yearOfCommonEra];
- // NSLog(@"year = %ld",year);
- //格式化日期
- NSDateFormatter *formatter =[[[NSDateFormatter alloc] init] autorelease];
- [formatter setDateFormat:@"yyyy年M月dd日 H点m分"];
- NSString *str = [NSString stringWithFormat:@"%@",
- [formatter stringFromDate:date]];
- NSLog(@"str:%@",str);
- }
- return 0;
- }
12-24