<p>从Python 3.6开始,您可以使用新的<code>%G</code>、<code>%u</code>和<code>%V</code>指令。见<a href="http://bugs.python.org/issue12006" rel="noreferrer">issue 12006</a>和<a href="https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior" rel="noreferrer">updated documentation</a>:</p>
<blockquote>
<p><code>%G</code><br/>
ISO 8601 year with century representing the year that contains the greater part of the ISO week (<code>%V</code>).</p>
<p><code>%u</code><br/>
ISO 8601 weekday as a decimal number where 1 is Monday.</p>
<p><code>%V</code><br/>
ISO 8601 week as a decimal number with Monday as the first day of the week. Week 01 is the week containing Jan 4.</p>
</blockquote>
<p>给定一个包含年份、周数和工作日数的字符串,可以很容易地将这些字符串解析为具有以下内容的日期:</p>
<pre><code>from datetime import datetime
datetime.strptime('2002 01 1', '%G %V %u').date()
</code></pre>
<p>或作为具有整数输入的函数:</p>
<pre><code>from datetime import datetime
def date_from_isoweek(iso_year, iso_weeknumber, iso_weekday):
return datetime.strptime(
'{:04d} {:02d} {:d}'.format(iso_year, iso_weeknumber, iso_weekday),
'%G %V %u').date()
</code></pre>