objective c - Converting string to NSDate -
this question has answer here:
- getting date [nsdate date] off few hours 3 answers
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
Post a Comment