Can any one give me an idea how to get the current date in milliseconds?
Casting the NSTimeInterval directly to a long overflowed for me, so instead I had to cast to a long long.
long long milliseconds = (long long)([[NSDate date] timeIntervalSince1970] * 1000.0);
The result is a 13 digit timestamp as in Unix.
Use this to get the time in milliseconds (long)(NSTimeInterval)([[NSDate date] timeIntervalSince1970])
.
You can use following methods to get current date in milliseconds.
[[NSDate date] timeIntervalSince1970];
OR
double CurrentTime = CACurrentMediaTime();
Source: iPhone: How to get current milliseconds?
NSTimeInterval milisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000);
An extension on date is probably the best way to about it.
extension NSDate {
func msFromEpoch() -> Double {
return self.timeIntervalSince1970 * 1000
}
}
Cconvert NSTimeInterval
milisecondedDate
value to nsstring
and after that convert into int
.