首页 > 编程 > Python > 正文

python获取当前日期和时间的方法

2019-11-25 17:34:38
字体:
来源:转载
供稿:网友

本文实例讲述了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程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表