How to send NSDate
in JSON Format through AFNetworking in iOS ? Json request -
{
"from_date" : "11/11/2014",
"to_date" : "11/11/2017"
}
Code -
// Formats the date chosen with the date picker.
- (NSString *)formatDate:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"dd'/'MM'/'yyyy"];
NSString *formattedDate = [dateFormatter stringFromDate:date];
return formattedDate;
}
- (void)updateToDateField:(id)sender
{
UIDatePicker *picker = (UIDatePicker*)toDateField.inputView;
toDateField.text = [self formatDate:picker.date];
}
// Storing the to date in NSString
dashboard.toDateString = toDateField.text;