跳至内容
贾京南的个人博客
返回

如何获取文件的创建或修改时间(精确到秒)

I want to get the fiel creation or docification time with seconds!!!

In windows, it seems impossible to see the exect time in Windows explorer, because it only shows the date and hour and minutes, missing the seconds!

Luckily, we have Python!

modified = os.path.getmtime(file)
print("Date modified: "+time.ctime(modified))
print("Date modified:",datetime.datetime.fromtimestamp(modified))

# out: 
# Date modified: Tue Apr 21 11:50:46 2015
# Date modified: 2015-04-21 11:50:46

Sort files from Glob by time

files.sort(key=os.path.getctime) from here.


分享此文:

上一篇
VS Code 常见问题
下一篇
点云用于分类