Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDateFormatter- stringFromDate not returning AM/PM

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"hh:mm:ss a"];
    NSLog(@"Today's Time: %@", [formatter stringFromDate:[NSDate date]]);

The above code just gives the following output Today's Time: 15:46:43 I want the output to be Today's Time: 3:46 PM. I surfed a lot and i did not find a way to show AM/PM. Would be really helpful if someone can help me find a way out. I am using XCode 6.3 and my Device has iOS 8.3 installed in it.

like image 853
Manju Basha Avatar asked May 22 '15 10:05

Manju Basha


1 Answers

Check your device settings for 24 hour time. If it is on, turn it off.

Your code is perfectly fine. I am getting output as shown below : Today's Time: 04:31:58 PM

If you don't want to show seconds use this code :

[formatter setDateFormat:@"hh:mm a"];
like image 125
Utsav Parikh Avatar answered Nov 02 '22 23:11

Utsav Parikh