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
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
3import pytz
4
5tz_NY = pytz.timezone('America/New_York')
6datetime_NY = datetime.now(tz_NY)
7print("NY time:", datetime_NY.strftime("%H:%M:%S"))
8
9tz_London = pytz.timezone('Europe/London')
10datetime_London = datetime.now(tz_London)
11print("London time:", datetime_London.strftime("%H:%M:%S"))
12