Retrieving current local time on iPhone?

后端 未结 7 645
我寻月下人不归
我寻月下人不归 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:18

    // get current date/time
    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    NSString *currentTime = [dateFormatter stringFromDate:today];
    [dateFormatter release];
    NSLog(@"User's current time in their preference format:%@",currentTime);
    

提交回复
热议问题