• 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: Date formatting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date formatting


  • Subject: Re: Date formatting
  • From: "Laurent Daudelin" <email@hidden>
  • Date: Fri, 26 Sep 2003 15:28:54 -0400

On 26/09/03 14:42, "Ryan McGann" <email@hidden> wrote:

> I've had this question for a while, and it's starting to really bother me.
> What is the correct way to format dates in Cocoa?
>
> We have an NSTableView with a column that displays dates, and we want to
> display the date (when in English) as something like 9/26/2003 12:24 pm.
> Ideally, it would also display today as "Today 12:24pm" like it did when our
> application was in Carbon, but since I'm not sure that's possible in Cocoa
> automatically, I'll just drop it for now.
>
> If we attach an NSDateFormatter to the column, and set its custom format to
> %m/%d/%y %I:%M %p, everything is fine in English...that ignores the user's
> preference for the 12/24 hour clock, but I can live with it. But in Japanese,
> the time shows up in a 12 hour clock without the AM/PM. Makes sense, so I try
> constructing the formatter on the fly, by combining NSShortDateFormatString
> and NSTimeFormatString. But NSTimeFormatString doesn't contain the AM/PM, and
> contains the seconds.
>
> It seems like in Carbon, this came out exactly how I wanted it no matter what
> language and no matter what the user's settings were for the 12/24 hour clock.
> How can I get this column to display correctly in any language using the
> format that I want, and conforms to the user's International locale settings?
>

I usually use '[aDate descriptionWithCalendarFormat:[[NSUserDefaults
standardUserDefaults] objectForKey:NSShortTimeDateFormatString] timeZone:nil
locale:nil]'. Not perfect, but at least it (kinda) respects the user's
settings...

-Laurent.
--
===========================================================================
Laurent Daudelin Developer, Multifamily, ESO, Fannie Mae
mailto:email@hidden Washington, DC, USA
************************* Usual disclaimers apply *************************
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Date formatting (From: Ryan McGann <email@hidden>)

  • Prev by Date: GCC3.3 and mid-function class declarations
  • Next by Date: NSMovieView screen corruption
  • Previous by thread: Date formatting
  • Next by thread: GCC3.3 and mid-function class declarations
  • Index(es):
    • Date
    • Thread