开发者

date localization in iphone

开发者 https://www.devze.com 2023-03-23 17:29 出处:网络
I need to localize thedate. i tried with following code but its giving wrong thing. For Example if my locale is \"US\" if i take date like(06 August 2011, 10:55 A.M.) from date picker and store in da

I need to localize the date. i tried with following code but its giving wrong thing.

For Example if my locale is "US" if i take date like(06 August 2011, 10:55 A.M.) from date picker and store in database then after i changed to locale to "Dutch" its working fine, it converts into dutch like (06 augustus 2011 10:55)

If i take date from date picker like (06 augustus 2011 10:55) for locale "Dutch" then I am changing to locale to "US" its display like(06 July 2011 10:55 A.M.),but it should be like(06 August 2011 10:55 A.M.).

I use below code for get date local date from string:

NSDate *past = [NSDate dateWithNaturalLanguageString:@"06 augustus 2011 10:55" locale:  [[NSUserDefa开发者_运维技巧ults standardUserDefaults] dictionaryRepresentation]];

please help out me


You're going about this the wrong way. You should not store localized strings in your database, just store the actual -date returned from UIDatePicker.

Use NSDate all the time, and only when you display to the user do you use a NSDateFormatter to show the date in the user's appropriate locale.

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消