python3 输出年月日类似2023-03-23
时间: 2023-07-02 19:18:12 浏览: 59
您可以使用Python3中的datetime库来打印当前日期,如下所示:
```python
from datetime import datetime
now = datetime.now()
print(now.strftime("%Y-%m-%d"))
```
这将输出当前日期,格式为YYYY-MM-DD,例如:2023-03-23。
相关问题
python 输出年月日时分秒
你可以使用 Python 中的 datetime 模块来输出当前的年月日时分秒。以下是示例代码:
```python
import datetime
now = datetime.datetime.now()
print("当前时间为:")
print(now.strftime("%Y-%m-%d %H:%M:%S"))
```
输出结果类似于:
```
当前时间为:
2021-06-24 16:25:10
```
python 输出年月日时分秒用下划线相连
你可以使用 Python 中的 datetime 模块来输出当前的年月日时分秒,并且用下划线相连。以下是示例代码:
```python
import datetime
now = datetime.datetime.now()
print("当前时间为:")
print(now.strftime("%Y_%m_%d_%H_%M_%S"))
```
输出结果类似于:
```
当前时间为:
2021_06_24_16_25_10
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)