The main things to note here are.

Get file modification time with getmtime

To get the file creation time with getctime

common use getmtime To ensure that the file is not the same as the comparison insurance

The time then obtained is UNIX time, so it needs to be converted again

Then output with strftime to string.

For everyone's reference.

import os
import datetime

#Get the file modification time, if you want to use the creation time, use os.path.getctime
unix_time = os.path.getmtime(file_path)
#Time Shift Object
datetimeObj = datetime.datetime.fromtimestamp(unix_time)
#Transfer string
dateStr = datetimeObj.strftime('%Y-%m-%d_%H%M%S')