Return to Snippet

Revision: 46051
at May 12, 2011 05:12 by bethjt1220


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

Initial URL


Initial Description


Initial Title
IOS Get Current Weekday with NSDate

Initial Tags
ios

Initial Language
iPhone