Spike7 Spike7 - 1 year ago 174
Python Question

How to convert nanoseconds of uptime into a readable date time format

I have extracted accerometer data from a android wearable. While looking at the data i realised the timestamp is not unix covertable. After research i saw the timestamp was actually nanoseconds in uptime. My question is the same as Accelerometer SensorEvent timestamp. However due to me not knowing Java i dont know how convert it using the solutions provided. Is there any python ways i can convert the nanoseconds in uptime into a readable date time format? An example of the timestamp would be "45900482044637".

Answer Source

To get the uptime in human-readable format in Python:

>>> from datetime import timedelta
>>> ns = 45900482044637
>>> print(timedelta(microseconds=round(ns, -3) // 1000))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download