-
-
Save nestserau/784471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This will convert DateTime (.NET) object serialized as JSON by WCF to a NSDate object. | |
*/ | |
+ (NSDate *)dateFromJSONTicks:(NSString *)inputString; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDate *)dateFromJSONTicks:(NSString *)inputString | |
{ | |
/* Input string is something like: "/Date(1292851800000+0100)/" where | |
1292851800000 is milliseconds since 1970 and +0100 is the timezone. */ | |
/* A range of NSMakeRange(6, 10) will generate "1292851800" from "/Date(1292851800000+0100)/" | |
as in example above. We crop additional three zeros, because "dateWithTimeIntervalSince1970:" | |
wants seconds, not milliseconds; since 1 second is equal to 1000 milliseconds, this will work. | |
Note: if you don't care about timezone changes, just chop out "dateByAddingTimeInterval:offset" part. */ | |
NSTimeInterval timeInterval = [[inputString substringWithRange:NSMakeRange(6, 10)] doubleValue]; | |
NSDate *result = [NSDate dateWithTimeIntervalSince1970:timeInterval]; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment