次のコードは機能しますが、汚い感じがします。オフセットのあるエポック日付を NSDate に変換するより標準的な方法はありますか?
- (NSDate *) dateFromJSONString: (NSString *) JSONString{
//expects JSON from .NET WCF Service in epoch ticks, ex:
//"timeScheduled":"\/Date(1348600140000+0100)\/"
NSString *date = [[JSONString stringByReplacingOccurrencesOfString:@"/Date(" withString:@""] stringByReplacingOccurrencesOfString:@")/" withString:@""];
NSString *offsetString = [date substringFromIndex:(date.length - 5)];
//convert to seconds
NSTimeInterval dateInterval = [date doubleValue] /1000;
//gets offset value in seconds - +0100 -> 100 -> 1 -> 3600
double offsetValue = ([offsetString doubleValue] / 100) * 60 * 60;
if ([[offsetString substringToIndex:1] isEqualToString:@"+"]) {
dateInterval = dateInterval + offsetValue;
}
else{
dateInterval = dateInterval - offsetValue;
}
NSDate *retVal = [[NSDate alloc]initWithTimeIntervalSince1970:dateInterval];
return retVal;
}