3

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?

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

The input integer is too big. OverflowError: Python int too large to convert to C long datetime

Raise OverflowError instead of ValueError if the timestamp is out of the range of values supported by the platform C gmtime() function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.