Can someone explain how i can calculate the time in "%Y%m%d%H%M%S%f" from my Firebase timestamp? I am receiving an error
signed integer is greater than maximum
when i do the following:
from datetime import datetime
def formatdatetime(sfd):
ts = datetime(sfd)
print(datetime.strftime("%Y%m%d%H%M%S%f", ts))
formatdatetime(1521508504583)
I'm guessing that I'm not taking in the milliseconds correctly?
First, you need to use datetime.datetime.fromtimestamp or datetime.datetime.utcfromtimestamp to parse the timestamp.
Second, I believe the timestamp you shared is in milliseconds rather than seconds, so you should divide it by 1000.
Example:
>>> dt = 1521508504583
>>> datetime.datetime.fromtimestamp(dt / 1000)
datetime.datetime(2018, 3, 19, 18, 15, 4)
>>> datetime.datetime.utcfromtimestamp(dt / 1000)
datetime.datetime(2018, 3, 20, 1, 15, 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With