objective c - Getting Null from NSDateFormatter -


i trying convert string nsdate, getting null.

sample string input = 8/8/2013 12:32:22 pm

code:

[self.dateformat setdateformat:@"mm/dd/yyyy hh:mm:ss a"]; nslog(@"date %@", [[communications objectatindex:x] objectforkey:@"dateupdated"]); nsdate *date = [[nsdate alloc] init]; date = [self.dateformat datefromstring:[[communications objectatindex:x] objectforkey:@"dateupdated"]]; nslog(@"date nsdate %@", [self.dateformat stringfromdate:date]); 

what doing wrong?

sample nslog output

2013-08-15 13:01:59.409 hd[478:907] date 8/8/2013 12:32:22 pm 2013-08-15 13:01:59.412 hd[478:907] date nsdate (null)   2013-08-15 13:01:59.418 hd[478:907] date 8/12/2013 9:45:18 2013-08-15 13:01:59.419 hd[478:907] date nsdate (null) 2013-08-15 13:01:59.421 hd[478:907] date 8/12/2013 9:45:20 2013-08-15 13:01:59.423 hd[478:907] date nsdate (null) 2013-08-15 13:01:59.430 hd[478:907] date 8/12/2013 4:10:49 pm 2013-08-15 13:01:59.431 hd[478:907] date nsdate (null) 

note: what's strange if run same code on simulator works fine , devices. reason, if run on handful of devices date, returns null...

it locale-dependent, with

[self.dateformat setlocale:[[nslocale alloc] initwithlocaleidentifier:@"en_us_posix"]]; 

it should work on devices.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -