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.
Asked
Active
Viewed 1,496 times
-4

dmaulikr
- 458
- 5
- 20
2 Answers
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
-
1Thank You @Jogendra.Com this helped. – dmaulikr Apr 07 '17 at 08:36
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