如何在Python中获取周数? [英] How to get week number in Python?

查看:158
本文介绍了如何在Python中获取周数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在今年6月16日(wk24)找到什么星期的数字与Python?

How to find out what week number is this year on June 16th (wk24) with Python?

推荐答案

datetime.date 有一个 isocalendar ()方法,返回一个包含日历周的元组:

datetime.date has a isocalendar() method, which returns a tuple containing the calendar week:

>>> datetime.date(2010, 6, 16).isocalendar()[1]
24

datetime.date.isocalendar()是一个实例方法以相应的顺序返回一个包含年份,周号和工作日的元组。

datetime.date.isocalendar() is an instance-method returning a tuple containing year, weeknumber and weekday in respective order for the given date instance.

这篇关于如何在Python中获取周数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆