【发布时间】:2015-09-10 16:12:57
【问题描述】:
标题说明了一切。我正在尝试获取为索引目的创建文件的年份。另外,如果这很重要,我会在 Windows 上。
【问题讨论】:
标签: python
标题说明了一切。我正在尝试获取为索引目的创建文件的年份。另外,如果这很重要,我会在 Windows 上。
【问题讨论】:
标签: python
这个问题已经有人问过了,这里简单说一下,看下面的代码:
import os.path, time
print "last modified: %s" % time.ctime(os.path.getmtime(file))
print "created: %s" % time.ctime(os.path.getctime(file))
这里是链接: How to get file creation & modification date/times in Python?
【讨论】:
所以这是解决方案:
import os
import datetime
#gives the create time as a unix timestamp
create_time = os.stat(<path to file>).st_ctime
#returns a datetime object
create_datetime = datetime.datetime.fromtimestamp(create_time)
#print the year
create_datetime.strftime("%Y")
【讨论】: