If I have an NSDate
object, how can I format an NSString to output only the first 3 letters of the Day (like Mon, Tue, Wed, Thu, Fri, Sat, Sun) and the first 3 letters of the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)?
Currently I'm using this NSDateFormatter
:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"MMMM dd yyyy";
NSDate *date = ...
NSString *dateString = [dateFormatter stringFromDate:date];
NSLog(@"dateString: %@",dateString);
// outputs August 09 2013
// I would like the output to be Fri, August 9
Edit
I've also tried using the NSDateComponent but I'm wondering if there's some shortcut to getting the abbreviations...
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date];
NSDateFormatter
. There is a link to "data formatters" which in turn has a link for "date formatters" which finally has a link to the page I referenced. It's real obvious ;) – rmaddy