1

how to convert epoch to time by assigning a particular epoch value to it. tried assigning values to a and calling it. couldnt able to do it.

import datetime

a=1529396478000

datetime.datetime.fromtimestamp(a).strftime('%c')
  • 1
    Possible duplicate of [JavaScript timestamp to Python datetime conversion](https://stackoverflow.com/questions/10286224/javascript-timestamp-to-python-datetime-conversion) – Minato Jan 22 '19 at 12:12

2 Answers2

1
import datetime

a=1529396478000
a /= 1000

print(datetime.datetime.utcfromtimestamp(a).strftime('%Y-%m-%d %H:%M:%S'))
Litvin
  • 330
  • 1
  • 9
0

try datetime.datetime.fromtimestamp(a).strftime('%Y-%m-%d %H:%M:%S')

I think a is missing a dot, a=1529396478.000 otherwise the year is 50434 resulting in a ValueError.

Frans
  • 799
  • 6
  • 7
  • got it thanks! is there an way of doing it using pandas without adding ( . ) – 艾瑪艾瑪艾瑪 Jan 22 '19 at 12:15
  • @hukkemaaru - Looking at the error I think you are running python 3.6 on a windows system and triggered a resolved bug : https://bugs.python.org/issue29097. Please update python and try again, the code works and you should not recieve this error. – Frans Jan 22 '19 at 12:26