# 示例代码:输出当前时间
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)
datetime
模块提供了处理日期和时间的功能。datetime.now()
返回当前的本地时间。print
函数输出当前时间,默认格式包含年、月、日、时、分、秒和微秒。strftime
方法可以将时间对象格式化为指定的字符串格式。例如,%Y-%m-%d %H:%M:%S
表示年-月-日 时:分:秒。上一篇:python中list代表什么
下一篇:python中turtle
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站