pythondateunix-timestamp

python get time stamp on file in mm/dd/yyyy-HH:MM format


I'm trying to get the datestamp on the file in mm-dd-yyyy-hh:mm format.

time.ctime(os.path.getmtime(file))

gives me detailed time stamp:

Fri Jun 07 16:54:31 2013

How can I display the output as:

06-07-2013-16:54

This is very similar to: python get time stamp on file in mm/dd/yyyy format

This is doing the half of what I want but I can't add hour and minute.

time.strftime('%m/%d/%Y', time.gmtime(os.path.getmtime(file)))

Solution

  • Just found it, I needed to add %H:%M like below:

    time.strftime('%m-%d-%Y-%H:%M', time.gmtime (os.path.getmtime(file)))