0

I am trying to indicate the months names , but my code just show me the number of months like : 3 , 4 , 12

[dateFormatter setDateFormat:@"MM"];
NSString *currMonth = [dateFormatter stringFromDate:today];
month.text = [NSString stringWithFormat:@"%@",currMonth];
Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40
iOS.Lover
  • 5,923
  • 21
  • 90
  • 162

5 Answers5

4

Change this format :

[dateFormatter setDateFormat:@"MM"];

to this :

[dateFormatter setDateFormat:@"MMMM"];
Mc.Lover
  • 4,813
  • 9
  • 46
  • 80
2

@Mc.Lover You shoud read the documentation first. Check out Managing Weekday Symbols in that.

Anil
  • 967
  • 10
  • 20
2

It's not clear if you want the Months or Weekdays from the question?

The month:

[dateFormatter setDateFormat:@"MMMM"];`

The Weekday:

[dateFormatter setDateFormat:@"EEEE"];

Both:

[dateFormatter setDateFormat:@"'Weekday:'EEEE  'Month:'MMMM "];

I refer to this list when I need to know the formats: http://www.alexcurylo.com/blog/2009/01/29/nsdateformatter-formatting/

Hubert Kunnemeyer
  • 2,261
  • 1
  • 15
  • 14
1

This would lead you in the right direction:

https://stackoverflow.com/a/2466033/127036

Community
  • 1
  • 1
Vibhor Goyal
  • 2,405
  • 2
  • 22
  • 35
1

Your question is about weekdays. Your code is about months. Confusion.

If you chase the links from the class doc you'll get to the unicode formatting documentation.

Also, the stringWithFormat:@"%@" in your last line is superfluous.

[dateFormatter setDateFormat:@"eee"];
NSString *weekday = [dateFormatter stringFromDate:today];
weekdayField.text = weekday;
bshirley
  • 8,217
  • 1
  • 37
  • 43