Navneet Sharma Navneet Sharma - 1 year ago 74
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download