擅长:python、mysql、java
<p>我相信<code>date.isocalendar()</code>将是答案。<a href="http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm" rel="noreferrer">This article</a>解释了ISO 8601日历背后的数学原理。查看Python文档<a href="http://docs.python.org/library/datetime.html#datetime.date.isocalendar" rel="noreferrer">datetime page</a>中的date.isocalendar()部分。</p>
<pre><code>>>> dt = datetime.date(2010, 6, 16)
>>> wk = dt.isocalendar()[1]
24
</code></pre>
<p>.isocalendar()返回一个3元组,其中包含(year,wk num,wk day)。<code>dt.isocalendar()[0]</code>返回年份,<code>dt.isocalendar()[1]</code>返回周数,<code>dt.isocalendar()[2]</code>返回周日。尽可能简单。</p>