NSDate * date = [NSDate date]; NSTimeInterval sec = [date timeIntervalSinceNow]; NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinc eNow:sec]; //设置时间输出格式: NSDateFormatter * df = [[NSDateFormatter alloc] init ]; [df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"]; NSString * na = [df stringFromDate:currentDate]; NSLog(@"系统当前时间为:%@",na);
//获得系统日期NSCalendar * cal=[NSCalendar currentCalendar]; NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit; NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate]; NSInteger year=[conponent year]; NSInteger month=[conponent month]; NSInteger day=[conponent day]; NSString * nsDateString= [NSString stringWithFormat:@"%4d年%2d月%2d日",year,month,day];NSLog(@"系统当前日期为:%@",nsDateString);