python打印现在时间
时间: 2023-09-04 19:13:05 浏览: 51
你可以使用Python的datetime模块来打印当前的时间。下面是一个示例代码:
```python
import datetime
now = datetime.datetime.now()
print("当前时间:", now)
```
这将会打印出当前时间,输出格式为:`当前时间:2021-05-19 13:50:00.123456`。
相关问题
python 打印时间
在Python中,可以使用datetime和time模块来打印时间。
下面是使用datetime模块打印当前时间的示例代码:
```python
import datetime
current_time = datetime.datetime.now()
print("当前时间:", current_time)
```
使用time模块打印当前时间的示例代码:
```python
import time
current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
print("当前时间:", current_time)
```
这两种方法都可以打印出当前时间,你可以根据自己的需要选择其中一种。
python打印时间日期
以下是两种Python打印时间日期的方法:
1. 使用datetime模块打印当前时间
```python
import datetime
# 打印当前时间
time1 = datetime.datetime.now()
print(time1)
```
2. 使用datetime模块打印按指定格式排版的时间
```python
import datetime
# 打印按指定格式排版的时间
time2 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(time2)
```