I can get milliseconds in Java with:
Date date=new Date() ;
System.out.println("Today is " +date.getTime());
How do I get milliseconds in objective C? I have to have the same result for both code.
I can get milliseconds in Java with:
Date date=new Date() ;
System.out.println("Today is " +date.getTime());
How do I get milliseconds in objective C? I have to have the same result for both code.
The documentation for Java Date.getTime() is:
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
For Objective-C the analogous method is:
- (NSTimeInterval)timeIntervalSince1970
Return Value: The interval between the receiver and the reference date, 1 January 1970, GMT.
An NSTimeInterval is a double
in seconds. So, this does it:
llrint (1000.0 * [date timeIntervalSince1970]);
to get you a long
(as Java produces).
Note: 'duplicate' answers do not produce a long
as the Java interface does; they produce a double
.