1from datetime import datetime
2now = datetime.now()
3print (now.strftime("%Y-%m-%d %H:%M:%S"))
4
5
6Output: 2020-06-19 10:34:45
1from datetime import datetime
2now = datetime.now()
3print("date and time now: ", now)
4
5#you can also personalize how the formats, example:
6dt = now.strftime("%d/%m/%Y %H:%M:%S")
7print("date and time now: ", dt)
8
9#the output will be
10#date and time now: 22/12/2020 01:19:32
1import datetime
2now = datetime.datetime.now()
3print ("Current date and time : ")
4print (now.strftime("%Y-%m-%d %H:%M:%S"))
5
6
1from datetime import datetime
2
3now = datetime.now().time().strftime("%H:%M:%S") # time object
4date = datetime.now().strftime("%Y-%m-%d") # date object
5print("date:",date)
6print("time =", now)
1from datetime import date
2
3today = date.today()
4print("Today's date:", today)
5