1import datetime
2
3today = datetime.datetime.now()
4date_time = today.strftime("%m/%d/%Y, %H:%M:%S")
5print("date and time:",date_time)
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)