Currently, I am working with an existing array of NSDates in the following format:
NSDate *today = [NSDate date]; //today is used as an example
NSTimeInterval interval = [today timeIntervalSince1970];
NSString *hexInterval = [NSString stringWithFormat:@"%08x", (int)interval];
NSLog(@"hexInterval %@", hexInterval);
The dates are outputted in a format such as 4ec2acf0
.
My goal is to turn these back into NSDates, as since they came from NSTimeInterval, I was wondering how I could turn it back into NSTimeIntervals given that all I have are these 8-character NSStrings.
My goal is:
//Turn NSString into NSTimeInterval here, then:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
Thanks!
You can parse hex with
NSScanner
, like this:Note that this approach truncates the time portion of
NSTimeInterval
. This happens at the point when you convertNSTimeInterval
toint
on this line: