objective c - Converting string to NSDate -


this question has answer here:

i trying use nsdateformatter convert following string nsdate: 2013-08-19 7:00 am.

however, following nsdate created: 2013-08-19 04:00:00 +0000. hour wrong.

my code below. don't know doing incorrectly.

nsdateformatter *dateformatter = [nsdateformatter new]; [dateformatter settimezone:[nstimezone systemtimezone]]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm a"]; nsstring *string = @"2013-08-19 7:00 am"; nsdate *datefromstring = [dateformatter datefromstring:string]; 

you're attempting use 24-hour format hours and am/pm indicator, , won't work. change line:

[dateformatter setdateformat:@"yyyy-mm-dd hh:mm a"]; 

to this:

[dateformatter setdateformat:@"yyyy-mm-dd hh:mm a"]; 

and you'll find code works.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -