NSDate Cookbook

Common dates

// Right now, you can remove the seconds into the day if you want
NSDate *today = [NSDate date];

// All intervals taken from Google
NSDate *yesterday = [today addTimeInterval: -86400.0];
NSDate *thisWeek  = [today addTimeInterval: -604800.0];
NSDate *lastWeek  = [today addTimeInterval: -1209600.0];

Formatting

 

NSDate from NSString

NSString *string = @"07/19/80";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yy"];
dateNS = [dateFormat dateFromString:string];