I am working with an API that returns a .NET DateTime object into my iOS application. I\'m a little confused at what\'s going on, the DateTime looks fine when it leaves the
Essentially what you're getting there is milliseconds from January 1st 1970 UTC, with the -0600 being the timezone offset. Take a look at this blog post http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx
You would probably have to write a custom NSDateFormatter to handle a date in that format, or you could format it in .NET (easier), output a string in JSON, and then use a standard NSDateFormatter.
From Parsing JSON dates on IPhone I found the following function to be perfect:
- (NSDate*) getDateFromJSON:(NSString *)dateString
{
// Expect date in this format "/Date(1268123281843)/"
int startPos = [dateString rangeOfString:@"("].location+1;
int endPos = [dateString rangeOfString:@")"].location;
NSRange range = NSMakeRange(startPos,endPos-startPos);
unsigned long long milliseconds = [[dateString substringWithRange:range] longLongValue];
NSLog(@"%llu",milliseconds);
NSTimeInterval interval = milliseconds/1000;
return [NSDate dateWithTimeIntervalSince1970:interval];
}
The RestKit library has an NSDateFormatter subclass for just this. Take a look here for inspiration:
https://github.com/RestKit/RestKit/blob/master/Code/Support/RKDotNetDateFormatter.h https://github.com/RestKit/RestKit/blob/master/Code/Support/RKDotNetDateFormatter.m