[英]converting string into date format with Python
Hi I am trying to convert this string in Python : '2019-01-10' into date format as 2019-01-10嗨,我正在尝试在 Python 中将此字符串:'2019-01-10' 转换为日期格式 2019-01-10
I have tried this code :我试过这个代码:
from datetime import datetime
date_time_str = '2019-01-10'
date_time_obj = datetime.strptime(date_time_str, '%y-%m-%d )
but i have a ValueError : time data '2019-01-10' does not match format '%y-%m-%d'但我有一个 ValueError :时间数据“2019-01-10”与格式“%y-%m-%d”不匹配
Can you help me please ?你能帮我吗 ?
%y
format specifier is 2 digits, use uppercase %Y
. %y
格式说明符是 2 位数字,使用大写%Y
。 Ref: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes参考: https : //docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
from datetime import datetime
date_time_str = '2018-06-29'
date_time_obj = datetime.strptime(date_time_str, '%Y-%m-%d')
try changing it to the above code.尝试将其更改为上面的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.