Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display just the 12 Hour Time format from an ISO 8601 Timestamp

Tags:

ios

So I want to display just the time that is passed from our server in a label in my iOS App but I'm having trouble trying to figure out how to set up the right NSDateFormatter. So for example I get this timestamp from the Server in this format: 2013-02-27T18:15:00-0800, and I basically want to display "10:15 AM" in a label but so far I haven't had any luck. I tried this below:

NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc] init] autorelease];
            [timeFormatter setDateFormat:@"HH:mm a"];
            NSString *newTime = [timeFormatter stringFromDate:timeDate];
            NSLog(@"the new time is: %@", newTime);

But the output shows my time as 18:15 PM.

I've been looking around and trying different combinations in the NSDateFormatter but I just can't seem to find the right one, any help would be appreciated since I know this is something simple that I'm overlooking but I just can't find it.

like image 574
Sal Aldana Avatar asked Feb 18 '23 09:02

Sal Aldana


1 Answers

HH stands for 24hr.

hh satnds for 12 hr.

Change accordingly.

like image 147
shyamsundar1988 Avatar answered Feb 20 '23 00:02

shyamsundar1988