python获取当前日期和时间的方法
时间:2021-11-29 16:24 作者:admin
本文实例讲述了python/' target='_blank'>python获取当前日期和时间的方法。分享给大家供大家参考。具体如下:
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程序设计有所帮助。
(责任编辑:admin)