python将字符串转化为datatime
时间: 2023-12-31 13:03:50 浏览: 142
Python-数据分析-Python入门数据分析与机器学习课件
Sure, I can assist you with that. Here's an example code to convert a string to datetime format in Python:
```
from datetime import datetime
string_date = '2021-09-15 16:30:00'
datetime_obj = datetime.strptime(string_date, '%Y-%m-%d %H:%M:%S')
```
In the above code, the `strptime` method is used to parse the string date, and the `%Y-%m-%d %H:%M:%S` format code is used to represent the string format. You can replace the `string_date` variable with the actual string date that you want to convert. Let me know if you have any further questions.
阅读全文