| title | category | layout | tags | date | |
|---|---|---|---|---|---|
python中string转换为datetime | python | post |
| 2018-06-07 00:00:24 |
python中将string转换为datetime类型比较简单。只要注意待转换字符串格式要跟正则表达式一致。另外还需要注意年月日的代表字母,比如年是%Y
from datetime import datetime
datetime_object = datetime.strptime('2018-04-26 11:30:00', '%Y-%m-%d %H:%M:%S')
print(type(datetime_object))
输出为:
<class 'datetime.datetime'>
本文介绍如何在Python中将字符串格式的日期转换为datetime对象。通过示例代码展示正确的转换方式及注意事项,帮助读者掌握日期格式转换技巧。
640

被折叠的 条评论
为什么被折叠?



