Retrieving current local time on iPhone?

后端 未结 7 644
我寻月下人不归
我寻月下人不归 2020-12-01 07:57

I\'m looking to get the current hour and minute on a user\'s iPhone for display in an app that doesn\'t show the status bar. Is there a simple way to do this?

7条回答
  •  执笔经年
    2020-12-01 08:25

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
    NSString *currentTime = [dateFormatter stringFromDate:[NSDate date]]
    [dateFormatter release]; dateFormatter = nil;
    

    I think you should try this. The timeZone is important.

提交回复
热议问题