'format error in python string to time conversion
When I try to display the string in time, I get a format error.
result3 = ''.join(file_name)
date_time_str = result3
result1 = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S')
print(result1)
The problem here is that ValueError:time data 20220308233355'does not match format '%Y-%m-%d%H:%M:%S' error occurs. Did I enter the wrong format? I want to mark 20220308233355 as yyyy-mm--dd hh:mm:ss.
Solution 1:[1]
yes, you wanna do this:
result1 = datetime.datetime.strptime(date_time_str, '%Y%m%d%H%M%S')
print(result1)
>> 2022-03-08 23:33:55
which is datetime type , if you want string in that format , you have to :
result1 = result1.strftime('%Y-%m-%d %H:%M:%S'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | eshirvana |
