python 时间格式化
时间: 2023-08-26 19:18:57 浏览: 88
Python中可以使用time模块来进行时间的格式化。可以使用time.strftime()函数将时间格式化为指定的字符串格式。例如,使用"%Y-%m-%d %H:%M:%S"格式可以将时间格式化为"年-月-日 时:分:秒"的形式。示例代码如下:
```python
import time
# 获取当前时间的格式化字符串
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 输出格式化后的时间
print(formatted_time)
```
输出结果将会是当前时间的格式化字符串形式。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [python time常用格式化](https://blog.csdn.net/qq_35834501/article/details/106539092)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [python格式化时间和日期](https://blog.csdn.net/ak739105231/article/details/131269651)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文