0

I seem to be adding +11 minutes to my desired date values when I am converting them using NSDateFormatter.

The startDate and endDate as NSDates on MyObject, printed to the console:

START DATE: 2011-11-28 18:00:00 +0000

END DATE: 2011-11-28 20:00:00 +0000


My NSDateFormatter:

NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];

[formatter setDateFormat:@"hh:MM a"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

Setting the dateRangeString:

NSString *dateRangeString = [NSString stringWithFormat:@"%@ - %@", 
                                 [formatter stringFromDate:self.startDate],
                                 [formatter stringFromDate:self.endDate]];

The wrong resulting dateRangeString:

Date Range: 18:11 PM - 20:11 PM

Why is it adding an extra 11 minutes to the times? What am I doing incorrect in my conversion? Am I forgetting something silly? SO, please help my sanity!

kturner
  • 1,091
  • 2
  • 10
  • 15

2 Answers2

4
[formatter setDateFormat:@"HH:mm a"];

MM is for months.

Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

Community
  • 1
  • 1
eric.mitchell
  • 8,501
  • 12
  • 50
  • 91
0

Because it's November, the 11th month.

Hot Licks
  • 44,830
  • 15
  • 88
  • 146