Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odd behavior with timeIntervalSince1970

I'm seeing an odd behavior with trying to get seconds since epoch in objective C. This:

NSString *nowTimestamp = [NSString stringWithFormat:@"%d", 
                             [[NSDate date] timeIntervalSince1970]];

Outputs 15907296, when the current timestamp should be 1243555623 (05/28/2009 @ 7:08pm EST). The system time on the iPhone is correct. I can't figure out for the life of me what I'm doing wrong. Any recommendations?

like image 642
Parrots Avatar asked May 28 '09 23:05

Parrots


1 Answers

timeIntervalSince1970 returns an NSTimeInterval, which is a typedef for double; %d is not the right formatter to print a double (you want %f).

like image 128
smorgan Avatar answered Sep 24 '22 08:09

smorgan