How do I get tenths of second, hundredth of second, millisecond, etc. from an NSTimeInterval
in Swift?
Asked
Active
Viewed 858 times
-3

JAL
- 41,701
- 23
- 172
- 300

Sebastian Castro
- 103
- 3
-
just divide it by 10, 100, 1000 – Leo Dabus Nov 24 '15 at 02:14
-
Of what? An `NStimeInterval`? `NSDate`? – JAL Nov 24 '15 at 02:19
1 Answers
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