1import datetime
2
3currentDT = datetime.datetime.now()
4print(str(currentDT))
5
6# prints XXXX-XX-XX XX:XX:XX.XXXXXX
7# or
8
9import datetime
10
11currentDT = datetime.datetime.now()
12
13print ("Current Year is: %d" % currentDT.year)
14print ("Current Month is: %d" % currentDT.month)
15print ("Current Day is: %d" % currentDT.day)
16print ("Current Hour is: %d" % currentDT.hour)
17print ("Current Minute is: %d" % currentDT.minute)
18print ("Current Second is: %d" % currentDT.second)
19print ("Current Microsecond is: %d" % currentDT.microsecond)
20# prints
21"""
22Current Year is: XXXX
23Current Month is: XX
24Current Day is: XX
25Current Hour is: XX
26Current Minute is: XX
27Current Second is: XX
28Current Microsecond is: XXXXXX
29"""
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
1from datetime import datetime
2
3start = datetime.now()
4# code ...
5print(datetime.now()-start)