Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting an NSDate with Abbreviated Month/Day Names

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];
like image 373
Bob Yousuk Avatar asked Aug 12 '13 21:08

Bob Yousuk


People also ask

How do you abbreviate month names in tableau?

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.

What is YYYY MM DD format?

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]

How do you abbreviate dates in Tableau?

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.


1 Answers

As per the link kindly provided by rmaddy, @"EEE, MMM d"; is the solution

like image 77
Bob Yousuk Avatar answered Oct 05 '22 23:10

Bob Yousuk