python格式化输出日期时间
时间: 2023-11-21 20:57:02 浏览: 297
以下是两种Python格式化输出日期时间的方法:
1. 使用time模块输出格式化日期时间字符串:
```python
import time
date_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print(date_str) # 输出:2022-08-18 16:30:00
```
2. 使用格式化字符串占位符输出带汉字的日期时间:
```python
import time
print(time.strftime('%Y{}%m{}%d{} %H{}%M{}%S{}', time.localtime()).format("年","月","日","时","分","秒")) # 输出:2022年08月18日 16时30分00秒
```