-3

How do I get tenths of second, hundredth of second, millisecond, etc. from an NSTimeInterval in Swift?

JAL
  • 41,701
  • 23
  • 172
  • 300

1 Answers1

2

NSTimeInterval is a representation of seconds as a typealias of Double. You can get the tenths, hundreths, etc. of a second by diving its value:

let timeInterval = NSTimeInterval(1.0) // 1 second

let tenth = timeInterval / 10.0 // 0.1
let hundreth = timeInterval / 100.0 // 0.01
let millisecond = timeInterval / 1000.0 // 0.001
nhgrif
  • 61,578
  • 25
  • 134
  • 173
JAL
  • 41,701
  • 23
  • 172
  • 300