获取当前时间

时间:2010-10-03 19:43:19

标签: iphone objective-c ios4

  

可能重复:
  Retrieving current local time on iPhone?

如何获得当前时间?(小时:分钟:秒)

1 个答案:

答案 0 :(得分:36)

NSDate *now = [NSDate date];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"hh:mm:ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSLog(@"The Current Time is %@",[dateFormatter stringFromDate:now]);
[dateFormatter release];