Get the Day from the date in iOS sdk

后端 未结 7 477
无人共我
无人共我 2021-01-16 12:36

In my app, want to get the day (i.e. Sunday, Monday,etc.) from the date.

My code is as follow:

NSDate *currentDate = [NSDat         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 13:09

    i am using this and it worked for me in iOS 8.4

    -(NSString *) extractDayFromDate {
         NSCalendar* calender = [NSCalendar currentCalendar];
         NSDateComponents* component = [calender components:NSCalendarUnitWeekday fromDate:[NSDate date]];
         return [[calender weekdaySymbols] objectAtIndex:([component weekday]-1)]; 
    }
    

提交回复
热议问题