What's the current time Date object time precision when it is initiated using Date()
? Does it capture the time to milliseconds?
let currentTime = Date()
print(currentTime) // 2022-10-09 09:13:39 0000
When I print the date it only shows 2022-10-09 09:13:39 0000
so I wonder if its precision is only to the second.
CodePudding user response:
Does it capture the time to milliseconds?
Yes, it does. print
ing a date shows a fixed string description omitting the fractional seconds. A hint is that TimeInterval
is defined as a floating point type (Double
).
You can prove it
let interval = Date().timeIntervalSince1970
print(interval)
which shows a real fractional part rather than a Is-floating-point-math-broken value like .00000003