输入年月日,输出星期英文缩写,并加上装饰物(20个字符宽度)用python
时间: 2023-05-17 10:02:54 浏览: 159
python实现某年某月是星期几
以下是代码:
```python
import datetime
date_str = input("请输入日期(格式为YYYY-MM-DD):")
date = datetime.datetime.strptime(date_str, "%Y-%m-%d")
weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
weekday_abbr = weekdays[date.weekday()]
print("{:-^20}".format(weekday_abbr))
```
输入示例:
```
请输入日期(格式为YYYY-MM-DD):2022-01-01
```
输出示例:
```
--------Sat---------
```
阅读全文