Get date from week number
问题 Please what\'s wrong with my code: import datetime d = \"2013-W26\" r = datetime.datetime.strptime(d, \"%Y-W%W\") print(r) Display \"2013-01-01 00:00:00\", Thanks. 回答1: A week number is not enough to generate a date; you need a day of the week as well. Add a default: import datetime d = "2013-W26" r = datetime.datetime.strptime(d + '-1', "%Y-W%W-%w") print(r) The -1 and -%w pattern tells the parser to pick the Monday in that week. This outputs: 2013-07-01 00:00:00 %W uses Monday as the first