How to get nsdate with millisecond accuracy?

前端 未结 3 1952
臣服心动
臣服心动 2020-12-11 00:26

I need to get time in millisecond accuracy. How can I get it from NSDate. Currently when I NSLog time, it is showing only upto seconds.

3条回答
  •  -上瘾入骨i
    2020-12-11 01:15

    For those who want to get the time in mili seconds (like in Java)

    double timestamp = [[NSDate date] timeIntervalSince1970];
    int64_t timeInMilisInt64 = (int64_t)(timestamp*1000);
    

    (tested with iOS7 and the iPhone simulator using Xcode 5)

提交回复
热议问题