为了账号安全,请及时绑定邮箱和手机立即绑定

求助python代码:os.path.getmtime(path),求解释

求助python代码:os.path.getmtime(path),求解释

ITMISS 2021-12-01 21:07:01
os.path.getmtime(path)Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch (see thetime module). Raise os.error if the file does not exist or is inaccessible.这是文档原文,试了一下,返回了一个极大的数,搞不太懂这个函数什么意思,有什么用呢?
查看完整描述

2 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

这是一个unix时间戳。可以使用datetime库来处理时间戳:


import datetime, os= os.path.getmtime('/')tt = datetime.datetime.fromtimestamp(t)ttt = tt.strftime('%Y'# 这是个时间格式化字符串,只能返回年份。


查看完整回答
反对 回复 2021-12-05
?
温温酱

TA贡献1752条经验 获得超4个赞

返回最近一次修改的时间戳,可以再格式化为你想要的时间格式

查看完整回答
反对 回复 2021-12-05
  • 2 回答
  • 0 关注
  • 406 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信