gpt4 book ai didi

python - 在Python中查找本周的星期一

转载 作者:行者123 更新时间:2023-12-03 15:35:34 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Getting the date of the first day of the week

(2 个回答)



Python: give start and end of week data from a given date

(4 个回答)


去年关闭。




我试图在 python 中获取本周的 00:00 的星期一时间戳。我知道对于特定日期,可以使用以下方法找到时间戳

baseTime = int(datetime.datetime.timestamp(datetime.datetime(2020,1,1)))

但是,我希望我的程序根据日期自动找出当前周的星期一是哪个日期,然后获取时间戳。也就是说,它会返回本周和下周不同的日期,意味着不同的时间戳。

我知道可以使用找到当前日期
import datetime
today = datetime.date.today()

提前致谢

最佳答案

I am trying to get the timestamp of monday at 00:00 of the current week in python



您可以使用 timedelta方法来自 datetime包裹。
from datetime import datetime, timedelta
now = datetime.now()
monday = now - timedelta(days = now.weekday())
print(monday)

输出
2020-01-27 08:47:01

关于python - 在Python中查找本周的星期一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59981999/

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