您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/2/20 21:52:28发布12次查看
本文实例讲述了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程序设计有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product