Convert Date to Integer in Swift

后端 未结 3 1297
暖寄归人
暖寄归人 2020-12-30 02:40

I am updating some of my old Swift 2 answers to Swift 3. My answer to this question, though, is not easy to update since the question specifically asks for NSDate

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 03:04

    If you are looking for timestamp with 10 Digit milliseconds since 1970 for API call then, below is code:

    Just 1 line code for Swift 4/ Swift 5

    let timeStamp = Date().timeIntervalSince1970

    print(timeStamp) <-- prints current time stamp

    1587473264

提交回复
热议问题