NSDate *date = [NSDate date];
NSLog(@"%@",date);
NSLog(@"%@",[date descriptionWithLocale:[NSLocale currentLocale]]);
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:60*60*12];
NSLog(@"%@",[date1 descriptionWithLocale:[NSLocale currentLocale]]);
NSDate *date2 = [NSDate distantFuture];
NSLog(@"%@",date2);
NSLog(@"%@",[date2 descriptionWithLocale:[NSLocale currentLocale]]);
NSDate *date3 = [NSDate distantPast];
NSLog(@"%@",[date3 descriptionWithLocale:[NSLocale currentLocale]]);
//NSDate的比较
NSDate *later= [date3 laterDate:date2];
NSLog(@"%@",[later descriptionWithLocale:[NSLocale currentLocale]]);
NSDate *earlier = [date3 earlierDate:date2];
NSLog(@"%@",[earlier descriptionWithLocale:[NSLocale currentLocale]]);
NSTimeInterval sc = [date timeIntervalSinceNow];
NSDate *currentDate = [[NSDate alloc]initWithTimeIntervalSinceNow:sc];
NSLog(@"%@",currentDate);
//NSDate和字符串的转换
NSDateFormatter *df = [[NSDateFormatter alloc]init];
df.dateFormat = @"yyyy-MM-dd hh:mm:ss";
//[df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"];
NSString *na = [df stringFromDate:date];
NSLog(@"系统当前时间为:%@",na);
//取出日期中的年、月、日、时、分、秒
NSCalendarDate *calendar = [NSCalendarDate calendarDate];
int year = [calendar yearOfCommonEra];
int month = [calendar monthOfYear];
int day = [calendar dayOfMonth];
NSLog(@"%4d-%02d-%02d",year,month,day);