参考链接: os.path.getatime(path)
参考链接: os.path.getmtime(path)
参考链接: os.path.getctime(path)
代码实验展示:
import os
import time
# --------------------------------------------------------#
filePath = r'我的文件.txt'
print('\n'+filePath)
accessTime = os.path.getatime(filePath)
print('访问时间:',accessTime,time.ctime(accessTime))
createTime = os.path.getctime(filePath)
print('创建时间:',createTime,time.ctime(createTime))
modifyTime = os.path.getmtime(filePath)
print('修改时间:',modifyTime,time.ctime(modifyTime))
# --------------------------------------------------------#
filePath = r'D:\Python\Python35\Lib\site-packages\jieba'
print('\n'+filePath)
accessTime = os.path.getatime(filePath)
print('访问时间:',accessTime,time.ctime(accessTime))
createTime = os.path.getctime(filePath)
print('创建时间:',createTime,time.ctime(createTime))
modifyTime = os.path.getmtime(filePath)
print('修改时间:',modifyTime,time.ctime(modifyTime))
控制台结果输出:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
加载个人及系统配置文件用了 1151 毫秒。
(base) PS C:\Users\chenxuqi\Desktop\News4cxq\my-experiments> & 'D:\Anaconda3\envs\pytorch_1.7.1_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2021.1.502429796\pythonFiles\lib\python\debugpy\launcher' '52628' '--' 'c:\Users\chenxuqi\Desktop\News4cxq\my-experiments\test2.py'
我的文件.txt
访问时间: 1618842007.5554655 Mon Apr 19 22:20:07 2021
创建时间: 1618841512.1419275 Mon Apr 19 22:11:52 2021
修改时间: 1618841876.5396962 Mon Apr 19 22:17:56 2021
D:\Python\Python35\Lib\site-packages\jieba
访问时间: 1618841059.3642726 Mon Apr 19 22:04:19 2021
创建时间: 1614405250.9173985 Sat Feb 27 13:54:10 2021
修改时间: 1614405252.3822095 Sat Feb 27 13:54:12 2021
(base) PS C:\Users\chenxuqi\Desktop\News4cxq\my-experiments> conda activate pytorch_1.7.1_cu102
(pytorch_1.7.1_cu102) PS C:\Users\chenxuqi\Desktop\News4cxq\my-experiments>