ios - In objective-c date picker issue -
i have send date server in "eee, dd mmm yyyy h:mm:ss a" format , date should save in json format "yyyy-mm-dd't'hh:mm:ss.sss'z'". please give me suggestions.
exact solution here.i tried sample 1 you.here solution.
nsdateformatter* formatter = [[nsdateformatter alloc] init]; [formatter setdateformat:@"eee, dd mmm yyyy h:mm:ss a"]; lbl.text = [formatter stringfromdate:[nsdate date]] nslog(@"the lbl text - %@",lbl.text);
the printed output is
the lbl text - thu, 28 jul 2016 2:44:56 pm
then need convert string date in same date format
[formatter setdateformat:@"eee, dd mmm yyyy h:mm:ss a"]; nsdate *date = [dateformatter datefromstring:lbl.text]; nslog(@"the date - %@",date);
in above code if not set date format "eee, dd mmm yyyy h:mm:ss a" returns nil date.so when date format set format same string format. printed result is
the date - 2016-07-28 09:14:56 +0000
then set date format whatever want because got date without nil.
[formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.sss'z'"]; nsstring *strdate = [dateformatter stringfromdate:date]; nslog(@"the strdate - %@",strdate);
final printed rsult is
the strdate - 2016-07-28t14:44:56.000z
Comments
Post a Comment