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

Time:11-29

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?

CodePudding user response:

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)
  • Related