Skip to content

Instantly share code, notes, and snippets.

@cemolcay
Last active March 4, 2020 08:10
Show Gist options
  • Save cemolcay/e8e3cad64da65cd80a50ed37310d2038 to your computer and use it in GitHub Desktop.
Save cemolcay/e8e3cad64da65cd80a50ed37310d2038 to your computer and use it in GitHub Desktop.
mach_absolute_time to seconds in Swift
var timebaseInfo = mach_timebase_info_data_t()
init() {
mach_timebase_info(&timebaseInfo)
}
func machAbsoluteToSeconds(machAbsolute: UInt64 = mach_absolute_time()) -> Double {
let nanos = Double(machAbsolute * UInt64(timebaseInfo.numer)) / Double(timebaseInfo.denom)
return nanos / 1.0e9;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment