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"""Imports the datetime package from the Python library"""
2from datetime import datetime
3
4"""Sets the variable now to the current date and time"""
5now = datetime.now()
6
7"""The variable current_time contains the string values of the current time"""
8current_time = now.strftime("%H:%M:%S")
9print("Current Time =", current_time)
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
2print(datetime.datetime.now()) #datetime.datetime.now() is the syntax