将 timedelta 计算转换为 " %A, %B %d, %Y" 的问题
Problems with turning a timedelta calculation into " %A, %B %d, %Y"
我想使用以下代码片段将未来几天的生成器变成可读的单词,我将使用 .strftime(" %A, %B %d, %Y") 将其存储在列表中。
base = datetime.today()
date_list = [base - timedelta(days=x) for x in range(0, 7)]
datescroll_list = ()
但是,返回的内容格式不可读。我所知道的将该格式转换为可读格式的方法不起作用。
如果您添加括号然后调用 strftime,您的代码工作正常:
from datetime import datetime,timedelta
base = datetime.today()
date_list = [(base - timedelta(days=x)).strftime(" %A, %B %d, %Y") for x in range(0, 7)]
print(date_list)
输出:
[' Saturday, June 20, 2015', ' Friday, June 19, 2015', ' Thursday, June 18, 2015', ' Wednesday, June 17, 2015', ' Tuesday, June 16, 2015', ' Monday, June 15, 2015', ' Sunday, June 14, 2015']
我想使用以下代码片段将未来几天的生成器变成可读的单词,我将使用 .strftime(" %A, %B %d, %Y") 将其存储在列表中。
base = datetime.today()
date_list = [base - timedelta(days=x) for x in range(0, 7)]
datescroll_list = ()
但是,返回的内容格式不可读。我所知道的将该格式转换为可读格式的方法不起作用。
如果您添加括号然后调用 strftime,您的代码工作正常:
from datetime import datetime,timedelta
base = datetime.today()
date_list = [(base - timedelta(days=x)).strftime(" %A, %B %d, %Y") for x in range(0, 7)]
print(date_list)
输出:
[' Saturday, June 20, 2015', ' Friday, June 19, 2015', ' Thursday, June 18, 2015', ' Wednesday, June 17, 2015', ' Tuesday, June 16, 2015', ' Monday, June 15, 2015', ' Sunday, June 14, 2015']