首页 > 代码库 > python获取当天日期

python获取当天日期

http://www.sharejs.com/codes/python/8032


import datetime # Get a date objecttoday = datetime.date.today() # General functions print "Year: %d" % today.yearprint "Month: %d" % today.monthprint "Day: %d" % today.dayprint "Weekday: %d" % today.weekday() # Day of week Monday = 0, Sunday = 6 # ISO Functionsprint "ISO Weekday: %d" % today.isoweekday() # Day of week Monday = 1, Sunday = 7print "ISO Format: %s" % today.isoformat() # YYYY-MM-DD formatprint "ISO Calendar: %s" % str(today.isocalendar()) # Tuple of (ISO year, ISO week number, ISO weekday) # Formatted dateprint today.strftime("%Y/%m/%d") ##该代码片段来自于: http://www.sharejs.com/codes/python/8032

python获取当天日期