18

I want to have the integer value of the following floating point value:

var floatingPointValue = NSDate().timeIntervalSince1970 * 1000

I don't care if the integer value of this floating point number is actually an integer or a string.

DrCachetes
  • 954
  • 1
  • 9
  • 30

3 Answers3

26

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)
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
1

Int64 is enough to hold the value you needed

let floatingPointValue = NSDate().timeIntervalSince1970 * 1000
let intValue = Int64(floatingPointValue)
jaiswal Rajan
  • 4,641
  • 1
  • 27
  • 16
1

The crucial part is to use Int64 instead of Int on 32-bit platforms. It will allow you to use 8 bytes of memory (from −9223372036854775808 to +9223372036854775807)

Int64(NSDate().timeIntervalSince1970 * 1000)
yoAlex5
  • 29,217
  • 8
  • 193
  • 205