在Python中,如何找到给定周的第一个星期一的日期? [英] In Python, how do I find the date of the first Monday of a given week?

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

问题描述

如果我有一个星期的数字(例如51)和一个给定的年份(如2008年),那么如何找到同一周的第一个星期一的日期?



非常感谢

解决方案

 >>>进口时间
>>>> time.asctime(time.strptime('2008 50 1','%Y%W%w'))
'Mon Dec 15 00:00:00 2008'
假设您周的第一天是星期一,请使用%U 而不是%W 如果你周的第一天是星期天。有关详细信息,请参阅 strptime 的文档。



更新:固定周数。 %W 指令是基于0的,所以第51周将输入50,而不是51。


If I have a certain week number (eg 51) and a given year (eg 2008), how do I find the date of the first Monday of that same week?

Many thanks

解决方案

>>> import time
>>> time.asctime(time.strptime('2008 50 1', '%Y %W %w'))
'Mon Dec 15 00:00:00 2008'

Assuming the first day of your week is Monday, use %U instead of %W if the first day of your week is Sunday. See the documentation for strptime for details.

Update: Fixed week number. The %W directive is 0-based so week 51 would be entered as 50, not 51.

这篇关于在Python中,如何找到给定周的第一个星期一的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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