• 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: Display either date part or time part in LOCAL format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Display either date part or time part in LOCAL format


  • Subject: Re: Display either date part or time part in LOCAL format
  • From: mmalc Crawford <email@hidden>
  • Date: Sun, 05 Jul 2009 01:46:05 -0700


On Jul 5, 2009, at 12:21 AM, Jacob Rhoden wrote:

I am probably overlooking something obvious (I hope) but what is the proper way to convert. either the Date or Time part of an NSDate to a localised string? I know I can do the following but its not exactly localised :(
NSDate *now = [[NSDate alloc] init];
NSDateFormatter *localDate = [[NSDateFormatter alloc] init];
[localDate setDateFormat:@"yyyy-MM-dd"];
NSString *date = [localDate stringFromDate:now];


What do you mean by "it's not exactly localised"?
If you specify a format string that has localisable components, you'll see them, e.g.


NSDate *now = [[NSDate alloc] init];

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ar_OM"];

NSDateFormatter *localDate = [[NSDateFormatter alloc] init];
[localDate setLocale:locale];
[localDate setDateFormat:@"yyyy/MMM/dd"];
NSString *date = [localDate stringFromDate:now];


date: ٢٠٠٩/يوليو/٠٥

(Note that the date separator is "/".)

Typically you're encouraged to use styles rather than specifying the format directly, since this takes the user's preferences into account -- see <http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW3 >.

mmalc


_______________________________________________

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


References: 
 >Display either date part or time part in LOCAL format (From: Jacob Rhoden <email@hidden>)

  • Prev by Date: Display either date part or time part in LOCAL format
  • Next by Date: Re: Yet another memory management question
  • Previous by thread: Display either date part or time part in LOCAL format
  • Next by thread: Wrap to Page method
  • Index(es):
    • Date
    • Thread