Jan Rüegg
Jan Rüegg

Reputation: 10035

IOS: Get current date/time with specific (non-localized) format

I want to get the current date/time in a very specific format like this:

2013-11-24_18_12_88

However, using the following code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];   
[dateFormatter setDateFormat:@"yyyy-MM-dd_hh_mm_ss"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];

I get this date string instead:

2013-11-24_18:12:88

How can I force the dateFormatter to not delete the "_" in my date format and replace them with ":"?

Upvotes: 1

Views: 207

Answers (1)

Droppy
Droppy

Reputation: 9721

You need to use HH instead of hh in the date formatting specifier:

@"yyyy-MM-dd_HH_mm_ss"
             ^^

Upvotes: 2

Related Questions