python获取当前时间年月日时分秒
时间: 2023-08-26 18:15:16 浏览: 149
你可以使用datetime模块中的datetime函数来获取当前时间的年、月、日、时、分、秒。以下是获取当前时间年月日时分秒的代码示例:
```python
import datetime
now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day
hour = now.hour
minute = now.minute
second = now.second
print("当前时间:{}年{}月{}日 {}时{}分{}秒".format(year, month, day, hour, minute, second))
```
这段代码会输出当前时间的年、月、日、时、分、秒的信息。你可以根据需要来调整输出格式。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *3* [python年月日时分秒](https://blog.csdn.net/KingOfOnePiece/article/details/108472075)[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^chatsearchT3_1"}} ] [.reference_item]
- *2* [【python】获取当前时间(年月日时分秒)](https://blog.csdn.net/weixin_42468475/article/details/127566739)[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^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文