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.
HH stands for 24hr.
hh satnds for 12 hr.
Change accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With