1import datetime
2print(datetime.datetime.now()) #datetime.datetime.now() is the syntax
1from datetime import datetime
2now = datetime.now()
3print (now.strftime("%Y-%m-%d %H:%M:%S"))
4
1import datetime
2now = datetime.datetime.now()
3print(now.year, now.month, now.day, now.hour, now.minute, now.second)
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
1
2from datetime import datetime
3
4now = datetime.now() # current date and time
5
6year = now.strftime("%Y")
7print("year:", year)
8
9month = now.strftime("%m")
10print("month:", month)
11
12day = now.strftime("%d")
13print("day:", day)
14
15time = now.strftime("%H:%M:%S")
16print("time:", time)
17
18date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
19print("date and time:",date_time)
20