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

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -