This is a simple code snippet which explains's you how to convert NSDate to NSString in iOS.
Create a string as NSString *myDate & a date formatter. Suppose we have picked a random date from date picker so that the date we have picked is already in NSDate format.
Now use this code snippet to convert NSDate to NSString-
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *myDate= [self.dateFormatter stringFromDate:datePickr.date];
Now myDate is a String that contains the date but in NSString format.
NOTE- Here “datePickr” is the instance of Datepicker that we have used to pick the date.
Thanks for reading hope it helps.
0 Comment(s)