Get the Day from the date in iOS sdk

后端 未结 7 476
无人共我
无人共我 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:11

     NSCalendar* calender = [NSCalendar currentCalendar];
    
     NSDateComponents* component = [calender components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
    
    int weekDay = [component weekday];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSString *weekdayString = [[formatter weekdaySymbols] objectAtIndex:weekDay - 1];
    
    NSLog(@"Day ::: %@", weekdayString);
    

提交回复
热议问题