NSDate
NSCalendar
NSDateFormatter
- NSDate *now=[NSDate date];
- NSCalendar *cal=[[NSCalendar alloc]
- initWithCalendarIdentifier:NSGregorianCalendar
- ];
- [cal setTimeZone:[NSTimeZone systemTimeZone]]; // 3
- NSDateComponents *dc = [cal components:(NSHourCalendarUnit|NSMinuteCalendarUnit|
- NSSecondCalendarUnit) fromDate:now]; // 4
- //now 2013-06-13 05:45:43 +0000
- NSLog(@"The time is%@",now);
- NSLog(@"The time is%d:%d:%d",[dc hour], [dc minute], [dc second]); // 5
- NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
- [dateFormatter setAMSymbol:(@"AM")];
- [dateFormatter setPMSymbol:@"PM"];
- // [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- [dateFormatter setDateFormat:@"dd/MM/yyyy hh:mmaaa"];
- NSDate *curDate=[NSDate date];
- NSString *str=[dateFormatter stringFromDate :curDate];
- NSLog(@"%@",str);
- NSCalendar *c=[NSCalendar currentCalendar];
- unsigned int unitFlags=NSYearCalendarUnit|NSMonthCalendarUnit|
- NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
- NSDateComponents *dd=[c components:unitFlags fromDate:curDate];
- int y=[dd year];
- int d=[dd day];
- NSLog(@"%d 年 %d日",y,d);