Posted By

bethjt1220 on 05/12/11


Tagged

ios


Versions (?)

IOS Get Current Weekday with NSDate


 / Published in: iPhone
 

  1. // get the current date
  2. NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
  3. [dateFormat setDateFormat:@"yyyy-MM-dd"];
  4. NSDate *now = [[NSDate alloc] init];
  5.  
  6. // get the weekday of the current date
  7. NSCalendar* cal = [NSCalendar currentCalendar];
  8. NSDateComponents* components = [cal components:NSWeekdayCalendarUnit fromDate:now];
  9. NSInteger weekday = [components weekday]; // 1 = Sunday, 2 = Monday, etc.

Report this snippet  

You need to login to post a comment.