Format error occurs when converting Python string time

Asked 1 weeks ago, Updated 1 weeks ago, 2 views

A format error occurs when trying to display the string in time.

    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 ValueError: time data '20220308233355' does not match format '%Y-%m-%d %H:%M:%S' There is an error, did I enter the wrong format? My 20220308233355 I want to mark yyyy-mm--dd hh:mm:ss.

python

2022-09-20 10:59

1 Answers

# str => datetime
object.strftime('yyyymmddhhmmss')
# # datetime => str
object.strptime('yyyy-mm--dd hh:mm:ss')


2022-09-20 10:59

If you have any answers or tips


© 2022 pinfo. All rights reserved.