ios - Check date format style in Objective-C -
how can check date in format getting response api , in getting dates converting date string according format confusion getting date in 2 format, yyyy-mm-dd't'hh:mm:ss.sss
, yyyy-mm-dd't'hh:mm:ss
include sss
, not, kindly tell me how can first check date format style , use date format according that.
here following using code converting string desired format.
nsstring *datestr = @"2016-01-18t13:28:06.357"; nsdateformatter *formatter = [[nsdateformatter alloc] init]; [formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.sss"]; nsdate *date = [formatter datefromstring:datestr];
looking response.
initially check like
nsdate *date; nsdateformatter *formatter = [[nsdateformatter alloc] init]; // check 2016-01-18t13:28:06.357 [formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.sss"]; // returns date , date = [formatter datefromstring:datestr]; // check if date empty or if(date == nil) { // add date format [formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss"]; date = [formatter datefromstring:datestr]; }
Comments
Post a Comment