2024-04-26 12:44:17 发布
网友
我需要使用python获取文件创建日期和时间。我试过了:
os.stat(r"path")[ST_CTIME]
但它正在回归:
这不是创建日期时间。有办法吗?在
来自bytes.com:
import os import time create_date = os.stat('/tmp/myfile.txt')[9] print time.strftime("%Y-%m-%d", time.gmtime(create_date))
它给出了:
您也可以尝试:
print time.gmtime(create_date) (2009, 11, 25, 13, 37, 9, 2, 329, 0)
更准确的时间戳。在
注意,time.gmtime()返回的时间返回GMT;其他函数,如localtime(),请参见the ^{} module documentation。在
time.gmtime()
localtime()
你确定不是吗?使用unixtimestamp.com它将转换为“01/18/2010@7:34am”,这至少有意义。在
时间戳以秒为单位从1970-01-01返回。在
为什么不呢?在
>>> import time >>> time.ctime(1263538277) 'Fri Jan 15 04:51:17 2010'
在我看来,这是一个有效的创作时间。在
来自bytes.com:
它给出了:
^{pr2}$您也可以尝试:
更准确的时间戳。在
注意,} module documentation 。在
time.gmtime()
返回的时间返回GMT;其他函数,如localtime()
,请参见the ^{你确定不是吗?使用unixtimestamp.com它将转换为“01/18/2010@7:34am”,这至少有意义。在
时间戳以秒为单位从1970-01-01返回。在
为什么不呢?在
在我看来,这是一个有效的创作时间。在
相关问题 更多 >
编程相关推荐