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

前端 未结 3 725
孤城傲影
孤城傲影 2021-02-07 01:06

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

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

gives me detailed time stamp Fri Jun

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 01:29

    from datetime import datetime
    from os.path import getmtime
    
    datetime.fromtimestamp(getmtime(file)).strftime('%m/%d/%Y')
    

提交回复
热议问题