猿问

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

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.
这是文档原文,试了一下,返回了一个极大的数,搞不太懂这个函数什么意思,有什么用呢?

ITMISS
浏览 407回答 2
2回答

慕田峪4524236

这是一个unix时间戳。可以使用datetime库来处理时间戳:import datetime, ost = os.path.getmtime('/')tt = datetime.datetime.fromtimestamp(t)ttt = tt.strftime('%Y') # 这是个时间格式化字符串,只能返回年份。

温温酱

返回最近一次修改的时间戳,可以再格式化为你想要的时间格式
随时随地看视频慕课网APP

相关分类

Python
我要回答