Rahul Kalidindi
Rahul Kalidindi

Reputation: 4736

How to get the Monday date of a week using the week number

How can I find out the Date of Monday if I pass the week number. For example, I need the Monday of the Week 24 of the year

Upvotes: 0

Views: 1074

Answers (1)

anon
anon

Reputation:

Fill out a NSDateComponents object with the information you have. Then you can ask the current NSCalendar what date corresponds to those components.

NSDateComponents *components = [NSDateComponents new];
components.weekday = 2;
components.weekOfYear = 24;
components.year = 2012;
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents: components];

The weekday property starts with Sunday = 1.

If you are on OS X 10.7 or newer you should use the property yearForWeekOfYear instead of year.

Upvotes: 2

Related Questions