gpt4 book ai didi

python - 如何在python中按日期名称获取日期?

转载 作者:行者123 更新时间:2023-12-05 04:20:45 24 4
gpt4 key购买 nike

<分区>

我有一个日期名称,例如星期一。当前日期是星期三。现在我想知道下周一的日期。我怎样才能在很短的时间内通过最佳实践来做到这一点。现在我正尝试用一堆 if 条件来做这件事,这让事情变得困惑而且非常困难。

这是我的代码:

day_time = timezone.now()
current_day = day_time.strftime("%A")
coming_day = "monday"
if coming_day == current_day:
day_time = day_time

if coming_day=="sunday" and coming_day == "monday":
day_time = day_time + timedelta(days=6)

if coming_day=="sunday" and coming_day == "tuesday":
day_time = day_time + timedelta(days=5)

if coming_day=="sunday" and coming_day == "wednesday":
day_time = day_time + timedelta(days=4)

if coming_day=="sunday" and coming_day == "thursday":
day_time = day_time + timedelta(days=3)

.........so on

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com