I have date, for example: 2012-02-07 14:09:46.109950 and I need timestamp as 1328623786.568740, there is my code:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSS"];
[dateFormat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDate *date = [dateFormat dateFromString:@"2012-02-07 14:09:46.109950"];
NSTimeInterval interval = [date timeIntervalSince1970];
[dateFormat release];
NSLog(@"%f", interval);
But now, I have such result 1328623786.110000, .110000 - is rounded. Please help me to get not rounded result.
function CFAbsoluteTimeGetCurrent();
or CFDateGetTimeIntervalSinceDate(CFDateRef theDate, CFDateRef otherDate);
or CFDateGetAbsoluteTime(CFDateRef theDate);
UPDATE: your value automatically rounded here
NSDate *date = [dateFormat dateFromString:@"2012-02-07 14:09:46.109950"];
NSLog(@"%@", [dateFormat stringFromDate:date]);
result:
2012-02-07 14:09:46.110000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With