views:

4567

answers:

3

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?

Thanks, Ben

+4  A: 

See this similar question for an answer. You will have to change it to your date format.

[[NSDate date] timeIntervalSince1970];

Chris Ballance
+6  A: 

See the documentation for NSDate, NSDateComponents, and NSDateFormatter.

Kristopher Johnson
+12  A: 
// 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);
mixolution
+1 Thanks dude :). You def. had the best answer here, although you don't really need the NSLog
SeniorShizzle