iPhone:如何获得当前毫秒?
获得当前系统时间毫秒的最佳方式是什么?
[[NSDate date] timeIntervalSince1970];
它将自纪元以来的秒数作为双精度返回。 我几乎可以肯定你可以从小数部分访问毫秒。
如果你正在考虑使用相对时间(例如游戏或动画),我宁愿使用CACurrentMediaTime()
double CurrentTime = CACurrentMediaTime();
  推荐的方法是哪一种;  NSDate从联网的同步时钟吸取,偶尔会在与网络重新同步时发生呃逆。 
它返回当前的绝对时间,以秒为单位。
如果您只需要小数部分(通常在同步动画时使用),
let ct = CACurrentMediaTime().truncatingRemainder(dividingBy: 1)
  我在iPhone 4S和iPad 3上发布了所有其他答案(发布版本)。  CACurrentMediaTime的开销最小。  timeIntervalSince1970比其他的慢得多,可能是由于NSDate实例化的开销,尽管它对于许多用例可能并不重要。 
  我建议CACurrentMediaTime如果你想最小的开销,并不介意添加Quartz框架依赖。  或者如果可移植性是您的首要任务,那么gettimeofday 。 
iPhone 4S
CACurrentMediaTime: 1.33 µs/call
gettimeofday: 1.38 µs/call
[NSDate timeIntervalSinceReferenceDate]: 1.45 µs/call
CFAbsoluteTimeGetCurrent: 1.48 µs/call
[[NSDate date] timeIntervalSince1970]: 4.93 µs/call
iPad 3
CACurrentMediaTime: 1.25 µs/call
gettimeofday: 1.33 µs/call
CFAbsoluteTimeGetCurrent: 1.34 µs/call
[NSDate timeIntervalSinceReferenceDate]: 1.37 µs/call
[[NSDate date] timeIntervalSince1970]: 3.47 µs/call
