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 (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com