Python中获取日期的方法
获取星期几
from datetime import datetime, date dayOfWeek = datetime.now().weekday() print(dayOfWeek) dayOfWeek = datetime.today().weekday() print(dayOfWeek)
注意:datetime类的weekday()方法可以获得datetime是星期几,注意weekday()返回的是0~6,是星期一到星期日。
python获取今日日期
import datetime today = datetime.date.today() print(today)
输出:2019-06-25
python获取昨日日期
import datetime today = datetime.date.today() zuotian = today- datetime.timedelta(days=1) print(zuotian)
更多技术请关注。