python convert to unix time code example
Example 1: unix to date python
>>> from datetime import datetime
>>> ts = int("1284101485")
>>> print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
... '2010-09-10 06:51:25'
Example 2: convert to timestamp python
import datetime
date = '18/05/2020 - 18:05:12'
date = datetime.datetime.strptime(date, "%d %m %Y - %H:%M:%S"")
date = datetime.datetime.timestamp(date)
Example 3: convert integer unix to timestamp python
import datetime
print(
datetime.datetime.fromtimestamp(
int("1284105682")
).strftime('%Y-%m-%d %H:%M:%S')
)