当前位置: 首页 > 图灵资讯 > 行业资讯> Python怎样根据日期判断周几

Python怎样根据日期判断周几

发布时间:2025-01-02 17:34:15

相关学习推荐:python教程

Python根据日期判断周几的方法:

一、概述

业务有一个需求,需要根据日期,判断周几。

二、代码

当前日期

importdatetime
today=datetime.datetime.now().weekday()+1
print(today)

执行输出:5

指定日期

importdatetime
week=datetime.datetime.strptime("2020801","%Y%m%d").weekday()+1
print(week)

执行输出:6

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09