Send datetime from iphone app to web service

From the iPhone application, I have to send the date as a parameter to the webservice method, where the server parsing logic is implemented using C #, .NET and JSON.

In my iPhone application, I format the date as:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
NSString *myDateString = [dateFormatter stringFromDate:SentOn];

I get an error message:

Error deserializing an object of type DashboardDataContract.Contracts.DashboardInputParams. The contents of DateTime '2013-04-04T12: 00: 00Z' does not start with '/ Date (' and ends with ') /', as required for JSON. '.

I tried various date formatting. Can anyone help me in this regard?

+5
source share
3 answers

JSON.Net ISO, , "2012-05-09T00:00:00Z", Microsoft JSON Microsoft "/Date(xxxxxxxxxxxx)/"

:

unsigned long long time=(([[NSDate date] timeIntervalSince1970])*1000);
NSString* dateTimeTosend= [NSString stringWithFormat:@"/Date(%lld)/",time];
+7

NSDate timestamp.

NSTimeInterval timestamp = [[NSDate date] timeInvervalSince1970];
0

You can create a category method in NSDate

- (NSString *)jsonDateString
{
    NSTimeInterval seconds = [self timeIntervalSince1970];
    return [NSString stringWithFormat:@"/Date(%.0f+0000)/",seconds*1000];

}
0
source

All Articles