Reputation: 214
I have a time picker which displays time in 12 Hour format. Internally i am converting it to 24 Hour format. The problem is, if the time taken is 10:24, it displays 10:01. i.e 'now' will have 10:24 and 'self.currentTime' will have 10:01. What am i doing wrong.
NSDate *now = [timePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:MM:SS";
self.currentTime = [dateFormatter stringFromDate:now];
NSLog(@"The Current Time is %@",self.currentTime);
Thank you.
Upvotes: 0
Views: 188
Reputation: 1500535
MM
is "month of year", not "minute". You also want "s" (for seconds) rather than "S" (for fractions of a second).
I suspect you want a format of HH:mm:ss
.
See the "date formatters" documentation for more inforamtion - in particular, UTS 35, tr35-25 for the most recent version of iOS.
Upvotes: 2