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
1import time
2timestamp = 1547281745
3datetime = time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timestamp))
4print(datetime)
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 datetime
2now = datetime.datetime.today()
3timestamp = datetime.datetime.timestamp(now)
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))
8
9# Output
10
11dt_object = "2018-12-25 09:27:53"
12type(dt_object) = <class 'datetime.datetime'>