Ank Ank - 1 year ago 121
Python Question

python get time stamp on file in mm/dd/yyyy format

I'm trying to get the datestamp on the file in mm/dd/yyyy format


gives me detailed time stamp
Fri Jun 07 16:54:31 2013

How can I display the output as

Answer Source

You want to use time.strftime() to format the timestamp; convert it to a time tuple first using either time.gmtime() or time.localtime():

time.strftime('%m/%d/%Y', time.gmtime(os.path.getmtime(file)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download