python 时间

来源:互联网 发布:mac php ext 目录 编辑:程序博客网 时间:2024/05/12 06:50
import datetimenow = datetime.datetime.now()printprint "Current date and time using str method of datetime object:"print str(now)printprint "Current date and time using instance attributes:"print "Current year: %d" % now.yearprint "Current month: %d" % now.monthprint "Current day: %d" % now.dayprint "Current hour: %d" % now.hourprint "Current minute: %d" % now.minuteprint "Current second: %d" % now.secondprint "Current microsecond: %d" % now.microsecondprintprint "Current date and time using strftime:"print now.strftime("%Y-%m-%d %H:%M")
Current date and time using str method of datetime object:2008-06-26 11:33:15.309236Current date and time using instance attributes:Current year: 2008Current month: 6Current day: 26Current hour: 11Current minute: 33Current second: 15Current microsecond: 309236Current date and time using strftime:2008-06-26 11:33

0 0