0

I'm trying to convert epoch to human-readable date but it is apparently giving wrong output. Below is my code that I'm using and it outputs 51700-02-27 20:20:00. When I convert this epoch using the epochconverter, it returns the correct time as shown in the screenshot below.

import time

epoch_time = 1569332262000

print(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(epoch_time)))

enter image description here

What am I doing wrong here?

I also tried to use datetime module for conversion but it returns ValueError: year 51700 is out of range which leads me to believe that the epoch time might be wrong?

from datetime import datetime

epoch_time = 1569332262000

value = datetime.fromtimestamp(epoch_time)
print(f"{value:%Y-%m-%d %H:%M:%S}")
2
  • 2
    1569332262000 This timestamp is in milliseconds, but fromtimestamp() only expects seconds. So this value is 1000 times larger than expected. Commented Feb 21 at 17:21
  • @JohnGordon that was indeed the issue. I don't know how did I miss this. Thanks very much ! Commented Feb 21 at 17:24

0

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.