When you're generating/parsing a date format that's supposed to be stable like this, you should control the locale/calendar used by the formatter instead of letting the user settings control it.

For example, your data can be entirely off when the user's calendar is not Gregorian.

Instead, you should specify the system locale, [NSLocale systemLocale], and the gregorian calendar, [[NSCalendar alloc] initWithCalendarIdentifier:@"gregorian"], explicitly.

Aki

On 2009/07/18, at 13:03, James Gillespie wrote:

Hi All,

Thanks in advance for any help on this issue. I have a file that uses the following format for date and times:

(4 digit year)-(2 digit month)-(2 digit day)T(2 digit hour, 0-23):(2 digit minute):(2 digit seconds)-(4 digit offset from GMT)
Example: 2009-07-17T17:12:20-0700

I am using an NSDateFormatter with a custom date format to read these dates.

                formatter = [[NSDateFormatter alloc] init];
                [formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
                [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];

On the Mac this works great for any combination of Region setting and 24hr/AM,PM settings. On the iPhone (both iPhone OS 2.2.1 and 3.0) this does not work if the Region setting is set to something that defaults to 24hr time (like UK, France, and Thai) but the time display setting is set by the user to AM/PM. For example: on the iPhone if in "Settings" you set the region to UK and turn 24-Hour Time off. When the phone is configured like this the above code wants to read and write dates with the following format.

(4 digit year)-(2 digit month)-(2 digit day)T(2 digit hour, 0-23):(2 digit minute):(2 digit seconds) (AM/PM)-(4 digit offset from GMT)
Example: 2009-07-17T17:12:20 PM-0700

This is not the behavior I would have expected. Am I configuring NSDateFormatter correctly? Is this a bug I should file in Radar? Again any help is greatly appreciated. We have an app in the App Store with this issue and it is causing some customers issues.

Thanks,
James
_______________________________________________

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/aki%40apple.com

This email sent to a...@apple.com

_______________________________________________

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