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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -