Reputation: 6480
I'm working with an API that returns timestamps in .NET ticks format which I believe is 100 nanoseconds since Jan 1, 0001. This ends up with an extremely large number such as 635492330000000 (just typing from memory).
When I get the number from the API it's in NSNumber but it's too big to convert to an Integer on a 32 bit device to do math and convert it into seconds. How can I convert it to an NSDate?
Upvotes: 1
Views: 199
Reputation: 37189
Use long long
it can handle the large number like this.You can Convert from NSSNumber
NSLog(@"%lld", [date longlongValue]);
Convert it to date.
NSNumber *dateNumber = @(635492330000000); //Your Number
NSDate *date = [NSDate dateWithTimeIntervalSince1970: ([dateNumber longLongValue]-621355968000000L)/10000.0]; //621355968000000L are ticks
This will calculate from 1 January 0001
This will give date as 2014-10-18 12:43:20 +0000
Upvotes: 1