I need to post a NSDate
object using HTTP post to parse.com.
I don't know how to convert it.
//1 nsdate
[params setObject:date forKey:kKeyDate];
//2 nsstring
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd T HH : mm : ss.SSSZ"];
NSString *newString = [dateFormat stringFromDate:date];
[params setObject:newString forKey:kKeyDate];
Params are serialized in the body of the Http request. I know that everything else I'm doing is correct because if I comment out adding the NSDate
to the params, then it works.
try this ..
NSDate *CurrentDate = [NSDate date];
NSDateFormatter *DATEFORMATER = [[NSDateFormatter alloc]init];
[DATEFORMATER setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS'Z'"];
[DATEFORMATER setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *DATE_STRING = [DATEFORMATER stringFromDate:CurrentDate];
If you are using iOS 10.0 or above, use the ISO8601DateFormatter class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With