您的位置:首页 > 编程语言 > Python开发

python 获取文件创建日期、修改日期 Get created & modified time of a file

2017-06-10 10:48 1211 查看
To update the filename according to its created time or modified time, a function is a good way.

def getMdate(file):
'''return: modified time of a file'''

import time

# os.stat return properties of a file
tmpTime = time.localtime(os.stat(file).st_mtime)
return time.strftime('%Y-%m-%d', tmpTime)


And with simple change of variables:

def getCdate(file):
'''return: created time of a file'''

import time

# os.stat return properties of a file
tmpTime = time.localtime(os.stat(file).st_ctime)
return time.strftime('%Y-%m-%d', tmpTime)


Both of which return date in yyyy-mm-dd format.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 函数 日期 属性
相关文章推荐