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 = 6print 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 = 7print iso format: %s % now.isoformat()# iso format, e.g. 2010-12-24t07:10:52.458593print iso calendar: %s % str(now.isocalendar())# tuple of (iso year, iso week number, iso weekday)# formatted dateprint now.strftime(%y/%m/%d)
希望本文所述对大家的python程序设计有所帮助。
