ios - NSString Date to NSDate -
this question has answer here:
- converting nsstring nsdate (and again) 16 answers
nsstring date nsdate in ios not displaying proper details. have nsstring date :
nsstring *strfinal = @"2016-10-20 12:00:00"; i following below method convert nsstring nsdate
nsstring *strfinal = @"2016-10-20 12:00:00"; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; // [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss"]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss"]; nsdate *datefromstring = [[nsdate alloc] init]; datefromstring = [dateformatter datefromstring:strfinal]; and out put :
string date : 2016-10-20 12:00:00
nsdate is: 2016-10-19 18:30:00 +0000
it generates different date , different format nsstring want same nsdate.
any appreciated. thanks
you have problems time zone , can solved adding line of code:
[dateformatter settimezone:[nstimezone timezonewithname:@"gmt"]]; you can set timezone by:
[dateformatter settimezone:[nstimezone systemtimezone]]; or [dateformatter settimezone:[nstimezone localtimezone]]; or [dateformatter settimezone:[nstimezone timezonewithname:@"utc"]];
Comments
Post a Comment