iphone - How do I convert a string that contains "am/pm" to an NSDate when the user's device is set to 24-Hour Time in iOS? -
i need convert nsstring nsdate, next code works long user's device isn't set 24-hour time.
class="lang-c# prettyprint-override">nsdateformatter *formatter = [[nsdateformatter alloc]init]; [formatter setdateformat:@"mm/dd/yyyy hh:mm:ss a"]; nsstring *atime = @"2/11/2013 12:00:00 am"; nsdate *adate = [formatter datefromstring:atime];
however, adate returns null when device in 24-hour time. help?
i think you're seeing side effect of behaviour described qa1480. apple has resolved presumably thought developers not obeying locales modifying prescribed date format unless explicitly not to.
you can accomplish adding:
formatter.locale = [[nslocale alloc] initwithlocaleidentifier:@"en_us_posix"]; /* , autorelease if not using arc */
which says 'the date format set explicitly want, please don't modify in way'.
iphone ios nsdate nsdateformatter
No comments:
Post a Comment