Also, if you need date and time in specific format, you can specify directive to format date and time. Create getDateTime3.py file with following content. This example have some sample formated date and time outputs.
import datetime
currentDT = datetime.datetime.now()
print (currentDT.strftime("%Y-%m-%d %H:%M:%S"))
print (currentDT.strftime("%Y/%m/%d"))
print (currentDT.strftime("%H:%M:%S"))
print (currentDT.strftime("%I:%M:%S %p"))
print (currentDT.strftime("%a, %b %d, %Y"))
OUTPUT:
2017-03-06 16:13:59
2017/03/06
16:13:59
04:13:59 PM
Mon, Mar 06, 2017
No comments