Python completes the following time format conversion?

< H1 > 20180402 purl 154101-> 2018-04-02 15:41:51 < / H1 >

clipboard.png
Please take a look. Thank you

Feb.28,2021

use datetime library


<br>def TimeFormat(str):

pdb.set_trace()
-sharp20180402:154101 -> 2018-04-02 15:41:01
time_stamp = ""
index = 0 
for c in str:
    if index == 4 or index == 6:
        time_stamp += '-' 
    if index == 8:
        time_stamp += ' ' 
        index = index + 1 
        continue
    if index == 11 or index == 13: 
        time_stamp += ':' 

    index = index + 1 
    time_stamp += c
    
return time_stamp
Menu