1import datetime
2now = datetime.datetime.now()
3print (now.strftime("%Y-%m-%d %H:%M:%S"))
4# key: https://strftime.org/
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
1
2from datetime import datetime
3
4now = datetime.now().time() # time object
5
6print("now =", now)
7print("type(now) =", type(now))
1
2import time
3
4t = time.localtime()
5current_time = time.strftime("%H:%M:%S", t)
6print(current_time)
7
1import datetime
2datetime.datetime.now()
3datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)
4
5print(datetime.datetime.now())
6#2009-01-06 15:08:24.789150