python返回当前日期和时间,python返回当前,import datet


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") #

评论关闭