Java
void test() {
Date startDateX = new Date(); // represents down to milliseconds
// Do a bunch of stuff
// ...
System.out.printf("%.3f", timeIntervalSinceNow(startDateX));
}
private Double timeIntervalSinceNow(Date date) { return 0.001 * (date.getTime() - System.currentTimeMillis()); } // The time interval between the date and the current date and time. If the date parameter is earlier than the current date and time, this property's value is negative.
Is equivalent to...
Objective-C
- (void) test {
NSDate *startDateX = [NSDate date];
// Do a bunch of stuff
// ...
NSLog(@"Time difference: %f", -[startDateX timeIntervalSinceNow]);
}
Or...
Swift 5
func test() {
let startDateX = Date()
// Do a bunch of stuff
// ...
print(String(format: "Time difference: %f", -startDateX.timeIntervalSinceNow))
}