On 28 Sep 2011, at 04:51, Vincent Spader wrote:

> 
> On Sep 27, 2011, at 1:41 AM, Gerriet M. Denkmann wrote:
> 
>> The following code produces an empty string:
>> 
>>      calender = [ [ NSCalendar autoupdatingCurrentCalendar ] retain ];
>>      NSString *dateTemplate = @"eeeyyyyMMMMddHHmmss";
>>      NSLocale *locale = [calender locale];   //      en_IE
>>      NSString *dateFormat = [ NSDateFormatter dateFormatFromTemplate: 
>> dateTemplate  options:0  locale: locale ];     //      EEE dd MMMM yyyy 
>> HH:mm:ss
>>      dateFormatter = [ [ NSDateFormatter alloc ] initWithDateFormat: 
>> dateFormat allowNaturalLanguage: NO ];
>>      [ dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4 ];    
>>      [ dateFormatter setLocale: locale ];
>>      [ dateFormatter setGeneratesCalendarDates: YES ];
>>      NSTimeZone *localTimeZone = [ calender timeZone ]; 
>>      [ dateFormatter setTimeZone: localTimeZone ];
>>      NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);
>> 
>> What am I missing?
> Creating an NSDateFormatter via -initWithDateFormat:allowNaturalLanguage: 
> will create a 10.0 style date formatter. 10.0 and 10.4+ date formatters have 
> completely different format strings, so when you call -setFormatterBehavior:, 
> the format string may not stick around. Here's what you want:
>       dateFormatter = [ [ NSDateFormatter alloc ] init];
>       [dateFormatter setDateFormat:dateFormat];
> 
> and the setFormatterBehavior: call is no longer necessary. You can find more 
> info in the "Formatting Behaviors and OS Versions" section of the 
> NSDateFormatter reference.

You are right. Now everything behaves as expected.
Thank you very much.

Kind regards,

Gerriet.

P.S. 
Is there a direct way to get the localized monthSymbols and shortWeekdaySymbols 
without using NSDateFormatter?

_______________________________________________

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

Reply via email to