Currently, test 32 is the str type. I would like to express the str type of test32 in time data. yyyy-mm-dd hh:mm:ss method... However, time data '22/03/0823:33:55.256' does not match format '%Y%m%d%H%M%S' error occurs. Is there any way?
for z in data:
if 'D:\System\iUTILITY\Tool\Curver\ToolBox\STG\i02-K01_S1_CEC_Update_Monintor_Analysis.xpsp' in z:
test30 = z.split(' ')[0:2]
test31 = ''.join(test30)
test32 = test31.split(',')[0]
print(type(test32))
test33 = datetime.datetime.strptime(test32, '%Y%m%d%H%M%S')
print(test33)
# print(test32)
To parse the date 22/03/0823:33:55.256
, you need to use format %y/%m/%d%H:%M:%S.%f
, like this:
datetime.datetime.strptime('22/03/0823:33:55.256', '%y/%m/%d%H:%M:%S.%f')
# Ouptut: datetime.datetime(2022, 3, 8, 23, 33, 55, 256000)
According to the document, %y
stands for the year without century, and %f
stands for the microsecond. Here's the document:
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.