Navneet Sharma Navneet Sharma - 5 months ago 29
Objective-C Question

How to get Day number of week from NSDate

I want to know the day number of week from NSDate.

Example:- Suppose today is 10th Oct 2016, Here Week number is 3rd which i got using

NSInteger week = [_calendar component:NSCalendarUnitWeekOfMonth fromDate:date];

Now I want to know the day number of current week, Which is 2nd for 10th Oct.


It will fetch you the day number i.e. 2. The day number are always same for every week. (1-7)

//Assuming your calendar is initiated like this
NSCalendar *_calendar = [NSCalendar currentCalendar];

//Fetch the day number
NSInteger day = [_calendar component:NSCalendarUnitWeekday fromDate:date];

Explore NSCalendar for more details here