[iOS] Double value cannot be converted to Int because the result would be greater than Int.max

因為把 date.timeIntervalSince1970 * 1000 轉成 int 會出錯,所以改用 Int64 再用 String() 包起來就不會顯示這一個 Error:

Double value cannot be converted to Int because the result would be greater than Int.max


解法:

Int64 is large enough to hold a time interval of some million years measured in milliseconds:

let milliSeconds = Int64(someDate.timeIntervalSince1970 * 1000)
let milliSecondsString = String(milliSeconds)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *