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];
Start by right clicking on any month across the Order Date Axis and select Format. You'll notice that the pane on the left changes from Data to Header. In the Header Pane select Dates and Abbreviation and you're done.
The ISO date format The international format defined by ISO (ISO 8601) tries to address all these problems by defining a numerical date system as follows: YYYY - MM - DD where. YYYY is the year [all the digits, i.e. 2012] MM is the month [01 (January) to 12 (December)] DD is the day [01 to 31]
Right-click the date dimension or the header in the view and select Format. In the Header section, select Abbreviation or First Letter in the "Date" menu.
As per the link kindly provided by rmaddy, @"EEE, MMM d";
is the solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With