1
在覈心運動中,數據以繼承自CMLogItem
的類返回,該類具有timestamp
屬性。 timestamp
是自設備啓動以來的一個TimeInterval
。在iOS中,使用Swift,你如何獲得iPhone啓動的時間?
設備啓動時如何獲取?
在覈心運動中,數據以繼承自CMLogItem
的類返回,該類具有timestamp
屬性。 timestamp
是自設備啓動以來的一個TimeInterval
。在iOS中,使用Swift,你如何獲得iPhone啓動的時間?
設備啓動時如何獲取?
從評論中,我能找到ProcessInfo.processInfo.systemUptime
這是自上次啓動以來的時間。由此看來,和Date()
,我可以通過開始的時間:
time_of_last_boot = Date() - ProcessInfo.processInfo.systemUptime
[這個問題](https://stackoverflow.com/questions/6911226/nslog-timestamp)具有通過在@gros答案好的方法。答案在Objective-C中,但轉換不應太難;基本上假設第一次更新的傳送足夠接近「現在」,您可以從「now」中減去時間戳以獲得啓動時間。 – Paulw11
[''CACurrentMediaTime()'](https://developer.apple.com/documentation/quartzcore/1395996-cacurrentmediatime)返回['mach_absolute_time'](https://developer.apple.com/documentation/kernel/1462446) -mach_absolute_time),這是自重新啓動以來的時間,'CACurrentMediaTime'會將轉換時間轉換爲秒數。 – Rob