datetime
常与time模块搭配
引入datetime:import datetime
1. 打印今天的日期
print(datetime.date.today()) # 输出2023-12-27
2. 类型转换
2.1 字符串转换为datetime
str = "2023-12-27 12:00:00" data = datetime.datetime.strptime(str, "%Y-%m-%d %H:%M:%S") print(type(data)) # 输出<class 'datetime.datetime'>