Python: How to convert Timestamp which of precision 9 to datetime object?

Question:

I am fetching crypto data from the ByBit exchange which is returning the timestamp field created_at_e9 in the following format: 1663315207126761200

The standard is 11 -13 digits but here are 20 digits. How do I fetch the DateTime from it?

Asked By: Volatil3

||

Answers:

You can look at this so see how to convert a timestamp into a datetime in python. And since the timestamp presision is 1e9 you can simply multiply the value by 1e-9 or divide it by 1e9 to get the timestamp in seconds.

from datetime import datetime
datetime.fromtimestamp(created_at_e9 * 1e-9)
Answered By: ShadowCrafter_01
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.