获取当前时间可以使用Python标准库中的datetime模块。具体的代码如下:
import datetime
# 获取当前时间
current_time = datetime.datetime.now()
# 格式化输出当前时间字符串
current_time_str = current_time.strftime("%Y-%m-%d %H:%M:%S")
print(current_time_str)
运行上述代码,会输出当前时间,并将其格式化为"年-月-日 时:分:秒"的字符串格式。