Python obtains the current date and time. python obtains the current date.
This example describes how to obtain the current date and time in python. Share it with you for your reference. The details are as follows:
Import datetime # Get a datetime objectnow = datetime. datetime. now () # General functions print "Year: % d" % now. yearprint "Month: % d" % now. monthprint "Day: % d" % now. dayprint "Weekday: % d" % now. weekday () # Day of week Monday = 0, Sunday = 6 print "Hour: % d" % now. hourprint "Minute: % d" % now. minuteprint "Second: % d" % now. secondprint "Microsecond: % d" % now. microsecond # ISO Functionsprint "ISO Weekday: % d" % now. isoweekday () # Day of week Monday = 1, Sunday = 7 print "ISO Format: % s" % now. isoformat () # ISO format, e.g. 2010-12-24T07: 10: 52.458593 print "ISO Calendar: % s" % str (now. isocalendar () # Tuple of (ISO year, ISO week number, ISO weekday) # Formatted dateprint now. strftime ("% Y/% m/% d ")
I hope this article will help you with Python programming.