datetime 返回 datetime.date() 而不仅仅是字典中的日期
如果我 print(final_date)
我会得到我正在寻找的回报 2022-02-26
。但是,不打印它而只是调用它,我得到了不期望的返回 {'date': datetime.date(2022, 2, 26)}
。但为了在字典中返回它,我必须调用它,因为如果我尝试打印它,我将得到 None
:
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
print(final_date)
job = {
'date': print(final_date)
}
print(job)
如果我只是调用它,我会得到不良结果。
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
print(final_date)
job = {
'date': final_date
}
print(job)
我怎样才能在字典中获得理想的结果。
编辑: 如何从以下代码中获得所需的日期回报
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
final_date1 = print(final_date)
print(final_date)
joblist = []
job = {
'date': final_date,
'career': 'arborist',
'salary': 65000
}
joblist.append(job)
print(joblist)
If I print(final_date)
I get the return I am looking for 2022-02-26
. However not printing it and just calling it I get an undesirable return {'date': datetime.date(2022, 2, 26)}
. But in order to return it in a dictionary, I have to call it because if I try to print it I will get None
:
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
print(final_date)
job = {
'date': print(final_date)
}
print(job)
and if I just call it I get the undesirable result.
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
print(final_date)
job = {
'date': final_date
}
print(job)
How can I get the desirable reuslt within a dictionary.
Edit:
How can I get the desired return from date from the following code
number_of_days = 5
final_date = datetime.today().date() - timedelta(days=int(number_of_days))
final_date1 = print(final_date)
print(final_date)
joblist = []
job = {
'date': final_date,
'career': 'arborist',
'salary': 65000
}
joblist.append(job)
print(joblist)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论