# 获取当前时间的示例代码
from datetime import datetime
# 获取当前时间
current_time = datetime.now()
# 打印当前时间
print("当前时间:", current_time)
# 如果需要格式化输出,可以使用 strftime 方法
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("格式化后的当前时间:", formatted_time)
from datetime import datetime 导入了 Python 内置的 datetime 模块中的 datetime 类。datetime.now() 返回一个表示当前本地时间的 datetime 对象。print("当前时间:", current_time) 将当前时间输出到控制台。strftime 方法用于将 datetime 对象格式化为指定格式的字符串。%Y-%m-%d %H:%M:%S 表示年-月-日 时:分:秒 的格式。上一篇:python运行
下一篇:python循环
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站