2024-05-15 14:14:44 发布
网友
datetime模块提供了一个方法date.isocalendar,在给定日期的情况下,该方法以([year], [week], [weekday])格式返回。我该怎么倒退?给定一个([year], [week], [weekday])元组,如何获取date对象?
datetime
date.isocalendar
([year], [week], [weekday])
date
编辑找到有解决方案的问题: What's the best way to find the inverse of datetime.isocalendar()?
我的解决方案有错误。在谷歌上看到了之前的问题,在下面的测试工作。(有关iso_to_gregorian的定义,请参见上述链接中的顶部回答问题)。(基本上可以找到iso年的开始日期,然后使用timedelta从day和week number中找到当前日期。
iso_to_gregorian
for i in range(-10000,10000,1): x = datetime.datetime.today().date() + datetime.timedelta(i) x_iso = datetime.datetime.isocalendar(x) assert iso_to_gregorian(*x_iso) == x
编辑找到有解决方案的问题: What's the best way to find the inverse of datetime.isocalendar()?
我的解决方案有错误。在谷歌上看到了之前的问题,在下面的测试工作。(有关
iso_to_gregorian
的定义,请参见上述链接中的顶部回答问题)。(基本上可以找到iso年的开始日期,然后使用timedelta从day和week number中找到当前日期。相关问题 更多 >
编程相关推荐