You can try a simple way to store microseconds separately, then replacein datetimeobject
>>> timestamp = 15179052980000000
>>> m_seconds = 38002
>>> dt = datetime.fromtimestamp(timestamp/10000000)
>>> dt
>>> datetime.datetime(2018, 2, 6, 16, 21, 38)
Then finally replace dtwith the desired microseconds
>>> dt.replace(micorsecond=m_seconds)
>>> dt
>>> datetime.datetime(2018, 2, 6, 16, 21, 38, 38002)
source
share