如何在 Python 中将字符串转换为日期时间或时间对象
文章目录
一、介绍
Pythondatetime和time模块都包含strptime()将字符串转换为对象的类方法。在本文中,您将使用strptime()将字符串转换为datetime对象struct_time()。
二、datetime使用将字符串转换为对象datetime.strptime()
该方法的语法datetime.strptime()是:
datetime.strptime(date_string, format)
该datetime.strptime()方法返回一个与格式解析的date_stringdatetime匹配的对象。两个参数都是必需的,并且必须是字符串。
有关中使用的格式指令的详细信息d
作者:无水先生