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

Re: Dates and localization


  • Subject: Re: Dates and localization
  • From: Kyle Hammond <email@hidden>
  • Date: Tue, 14 Jan 2003 17:15:31 -0600

Hi,

In order to localize your displayed dates, you need to use the locale: parameter of the -descriptionWithCalendarFormat:locale: method. This is how I accomplish the task:

NSString *dateString;
// theDate is an NSCalendarDate object.
dateString = [ theDate descriptionWithCalendarFormat:[ [ NSUserDefaults standardUserDefaults ]
objectForKey:NSDateFormatString ] locale:
[ NSCalendarDate systemDefinedLocale ] ];

I've added a category to NSCalendarDate to give me the system defined locale settings:

+ (NSDictionary *)systemDefinedLocale
{
NSDictionary *locale;
NSUserDefaults *defaults = [ NSUserDefaults standardUserDefaults ];

locale = [ NSDictionary dictionaryWithObjectsAndKeys:
[ defaults objectForKey:NSTimeDateFormatString ], NSTimeDateFormatString,
[ defaults objectForKey:NSAMPMDesignation ], NSAMPMDesignation,
[ defaults objectForKey:NSMonthNameArray ], NSMonthNameArray,
[ defaults objectForKey:NSShortMonthNameArray ], NSShortMonthNameArray,
[ defaults objectForKey:NSWeekDayNameArray ], NSWeekDayNameArray,
[ defaults objectForKey:NSShortWeekDayNameArray ], NSShortWeekDayNameArray,
nil ];

return locale;
}

Of course, you can use the same code to display other calendar formats if you want, such as the short date format, or the date with time.

Best regards,
Kyle

On Monday, January 13, 2003, at 02:47 PM, cocoa-dev-
email@hidden wrote:

Date: Mon, 13 Jan 2003 11:12:00 -0800
Subject: Dates and localization
From: Ian Gillespie <email@hidden>
To: email@hidden

Hi,

My program uses dates a lot. I was wondering how I make it so that
when I use my program with one of the languages it is translated to, it
will display the date in the correct language?

TIA

---------------------
Kyle Hammond
email@hidden

http://www.CodeBlazer.com/ - multimedia software solutions
http://www.snowmintcs.com/ - personal finance software
http://www.cpinternet.com/~em002400/ - my personal home page
_______________________________________________
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.

  • Prev by Date: Double-click action in an NSOutlineView
  • Next by Date: Re: COM on mac
  • Previous by thread: Dates and localization
  • Next by thread: WebCore and PDF
  • Index(es):
    • Date
    • Thread