python以mm / dd / yyyy格式获取文件上的时间戳 [英] python get time stamp on file in mm/dd/yyyy format

查看:100
本文介绍了python以mm / dd / yyyy格式获取文件上的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以mm / dd / yyyy格式获取文件中的日期戳记

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

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

给我详细的时间戳 Fri Jun 07 16:54:31 2013

如何将输出显示为 06/07/2013

推荐答案

你想使用 time.strftime() 格式化时间戳;首先使用 时间将其转换为时间元组。 gmtime() time.localtime()

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)))

这篇关于python以mm / dd / yyyy格式获取文件上的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆