0

I am trying to get date from week day and year . It work and get correct Output. But when i am changing CalendarIdentifier then it will show wrong output.

Here is my code

when i am setting CalendarIdentifier is NSGregorianCalendar

 NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:2013];
[components setWeek:2];
[components setWeekday:1];

NSDate *resultDate = [gregorian dateFromComponents:components];
output is :-  2013-01-05 18:30:00 +0000

When i am changing CalendarIdentifier is NSIndianCalendar

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSIndianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:2013];
[components setWeek:2];
[components setWeekday:1];

NSDate *resultDate = [gregorian dateFromComponents:components];
Output is :- 2091-03-24 18:30:00 +0000

what am i doing wrong ?.. Thanks in advance..

EDIT

According to Midhun MP answer my output is correct. now my problem is if i am using NSGregorianCalendar
output is :- 2013-01-05 18:30:00 +0000 day of that date is saturday.

According to NSGregorianCalendar saturday is start of week and friday is end of week . I want find similar start and end of week i.e Monday and sunday in india or it is different ??? .

Kalpesh
  • 5,336
  • 26
  • 41

1 Answers1

2

The output is correct.

Indian Calendar is 78 Years back of Gregorian Calendar. So 2013 in Indian Calendar is equal to 2091 in Gregorian Calendar.

Also the first month of Indian Calendar is the Third Month of Gregorian Calendar (March)

2013 (Indian Calendar)       + 78  = 2091 (Gregorian Calendar)
3 (March in Indian Calendar) + 2   = 5 (May in Gregorian Calendar)

Likewise there is change in day also.

Reference : Wikipedia

Midhun MP
  • 103,496
  • 31
  • 153
  • 200