[英]How to convert a string into datetime format
I'm trying to convert strings in a list to datetime format on Python. I am unable to use pd.DateTime
at the moment.我正在尝试将列表中的字符串转换为 Python 上的日期时间格式。目前我无法使用
pd.DateTime
。 The imported datetime
package doesn't seem to work.导入的
datetime
时间 package 似乎不起作用。 I'm new to this.我对此很陌生。
Please help.请帮忙。
Cheers.干杯。
You should consider using official datetime formats您应该考虑使用官方日期时间格式
Example:例子:
from datetime import datetime
#datetime(year, month, day)
date = datetime(2018, 11, 28)
# datetime(year, month, day, hour, minute, second, microsecond)
date = datetime(2017, 11, 28, 23, 55, 59, 342380)
you can use strptime
你可以使用
strptime
from datetime import datetime, strptime
my_datetime_list = [strptime(string_date, '%y-%m-%d') for string_date in list_of_string_dates]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.