Python DateTime module NOTES
import datetime
# full date with time (ms)
print(datetime.datetime.now())
# only date
date_obj = datetime.date.today()
print(date_obj)
# month, year, day individually
obj1 = datetime.date.today().month
obj2 = datetime.date.today().year
obj3 = datetime.date.today().day
print(obj1,obj2,obj3)
# time without microseconds
samay = datetime.datetime.now()
print("THIS -->",samay.replace(microsecond=0))
# only time
onlyTime = datetime.datetime.now()
print(onlyTime.strftime("[%H:%M:%S]\n"))
Comments
Post a Comment