user1511244
user1511244

Reputation: 725

Using NSDateFormatter on iOS

I am currently using an NSDateFormatter on my application to show the date in the format that i want. My NSDateFormatter looks like this : [formatter setDateFormat:@"MMM dd, yyyy hh:mm"]; which would give me dates like : Sep 02 , 2012 08:30 . I have 2 questions. i want to show the time in military time how can i do that with the formatter? I know how to show the AM/PM but i would like the time above to look 20:30. Secondly how can i make the month appear as a number? September would be 09 .

Upvotes: 1

Views: 178

Answers (2)

Henri Normak
Henri Normak

Reputation: 4725

This site has a nice table with the format specifiers you can use, follow up from that.

In this case, you should use [formatter setDateFormat:@"MM dd, yyyy HH:mm"]; To get 09 02, 2012 20:30

Upvotes: 3

Joe
Joe

Reputation: 57169

Use capital H for the hour and only two M's for the month.

[formatter setDateFormat:@"MM dd, yyyy HH:mm"];

Upvotes: 0

Related Questions