I’m trying to convert timestamp (NSTimeInterval) to date format. I’m getting the correct current date (day-month-year) but the time is not right. Here is my code. How do I fix it to get the current time correctly? Thanks in advance.
- (NSString*)formatTimestamp:(NSTimeInterval)timeStamp
{
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:timeStamp];
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd-MM-yyyy HH:mm:ss:SSS zzz"];
NSString *dateString=[formatter stringFromDate:date];
[formatter release];
return dateString;
}
Maybe I misunderstood something but I think your comparison is not right…
NSLog‘s time is current time andUIEvent‘stimestampis the number of seconds since system startup (and you add it to current time with[NSDate dateWithTimeIntervalSinceNow:])…If you want absolute datetime of an
UIEventyou need to get system startup date first, which is not so easy… and then addUIEvent‘stimestamp.You can use
with
Cf. Generating iPhone UIEvent Timestamps