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 date
2
3today = date.today()
4print("Today's date:", today)
1
2from datetime import datetime
3
4now = datetime.now()
5
6current_time = now.strftime("%H:%M:%S")
7print("Current Time =", current_time)
8
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
3# datetime object containing current date and time
4now = datetime.now()
5
6print("now =", now)
7
8# dd/mm/YY H:M:S
9dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
10print("date and time =", dt_string)
11
12# now = 2021-06-25 07:58:56.550604
13# date and time = 25/06/2021 07:58:56
1from datetime import datetime
2now = datetime.now()
3print (now.strftime("%Y-%m-%d %H:%M:%S"))
4