1import datetime
2date = '18/05/2020 - 18:05:12'
3
4# convert string to datetimeformat
5date = datetime.datetime.strptime(date, "%d %m %Y - %H:%M:%S"")
6
7# convert datetime to timestamp
8date = datetime.datetime.timestamp(date)
1from datetime import datetime
2
3timestamp = 1586507536367
4dt_object = datetime.fromtimestamp(timestamp)
5
1from datetime import datetime
2
3timestamp = 1545730073
4dt_object = datetime.fromtimestamp(timestamp)
5
6print("dt_object =", dt_object)
7print("type(dt_object) =", type(dt_object))
1import time
2import datetime
3s = "01/12/2011"
4time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1import time
2from datetime import datetime
3d = datetime(2017, 6, 11, 0, 0)
4
5unixtime = time.mktime(d.timetuple())
6
1
2from datetime import datetime
3
4timestamp = 1545730073
5dt_object = datetime.fromtimestamp(timestamp)
6
7print("dt_object =", dt_object)
8print("type(dt_object) =", type(dt_object))
9