Zeeshan Anjum
Zeeshan Anjum

Reputation: 148

Python: strftime, gmtime output not correct

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}")

Upvotes: 0

Views: 32

Answers (0)

Related Questions