-4

How can I get current month not as "Jan" but I want it in this format "1", in short I want current month as number because I want to append that number into string to complete URL Link for JSON Parsing. Thank you in advance.

dmaulikr
  • 458
  • 5
  • 20

2 Answers2

4

Try this you will get month number

NSDate *date = [NSDate date];
NSDateFormatter *dateFor = [[NSDateFormatter alloc]init];
[dateFor setDateFormat:@"MM"];
//[dateFor setDateFormat:@"M"]; // Use single M for avoid 0 before month number
NSString *monthNumber = [dateFor stringFromDate:date];

Hope it will help..

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
0

You can use NSCalendar to get NSDateComponents from it:

NSCalendar *calendar = [[NSCalendar alloc] init];
NSDateComponents *components = [calendar components: NSMonthCalendarUnit fromDate:date];

NSInteger month = [components month];
psci
  • 903
  • 9
  • 18