• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting weekday name from weekday number?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting weekday name from weekday number?


  • Subject: Re: Getting weekday name from weekday number?
  • From: Dave DeLong <email@hidden>
  • Date: Tue, 18 Oct 2011 15:21:30 -0700

Quick idea off the top of my head:

Ask an NSDateFormatter for its shortWeekdaySymbols (returns an NSArray of NSStrings) and index into that with your weekday number.

Other than that, the correct way to do this is to construct an NSDate with the appropriate weekday and then use a date format of "EEE" to get the short weekday name.

Dave

On Oct 18, 2011, at 3:18 PM, Rick Mann wrote:

> Hi. Given a day-of-week number, what's the best way to get the abbreviated name of that weekday? I've tried using NSDateComponents in various ways (stand-alone, building off the current date, etc.) to get at it (by using NSDateFormatter on the resulting date), but none seem to work. Basically, setting the weekday on NSDateComponents seems to do nothing.
>
> Matters are complicated by the fact that two of the three format specifiers for weekday name use the "local" weekday number, which can vary by locale.
>
> Any suggestions? I could just roll my own and localize it, but I'd rather just use what the OS provides.
>
> The only other thing I can think to do is start with a known date for, say, Sunday, and add to that the weekday number I have, and the convert that date to a string formatted as a weekday name.
>
> Thanks,
>
> --
> Rick
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting weekday name from weekday number?
      • From: Rick Mann <email@hidden>
References: 
 >Getting weekday name from weekday number? (From: Rick Mann <email@hidden>)

  • Prev by Date: Getting weekday name from weekday number?
  • Next by Date: Source list groups hidden by default
  • Previous by thread: Getting weekday name from weekday number?
  • Next by thread: Re: Getting weekday name from weekday number?
  • Index(es):
    • Date
    • Thread