Get current date in milliseconds

前端 未结 12 768
别跟我提以往
别跟我提以往 2020-12-04 10:23

Can any one give me an idea how to get the current date in milliseconds?

相关标签:
12条回答
  • 2020-12-04 11:01

    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.

    0 讨论(0)
  • 2020-12-04 11:07

    Use this to get the time in milliseconds (long)(NSTimeInterval)([[NSDate date] timeIntervalSince1970]).

    0 讨论(0)
  • 2020-12-04 11:08

    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?

    0 讨论(0)
  • 2020-12-04 11:11
    NSTimeInterval milisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000);
    
    0 讨论(0)
  • 2020-12-04 11:11

    An extension on date is probably the best way to about it.

    extension NSDate {
        func msFromEpoch() -> Double {
            return self.timeIntervalSince1970 * 1000
        }
    }
    
    0 讨论(0)
  • 2020-12-04 11:14

    Cconvert NSTimeInterval milisecondedDate value to nsstring and after that convert into int.

    0 讨论(0)
提交回复
热议问题