python getatime() 查看文件的访问时间

import time,os

def main():
    
    file_name=r'C:\Temp\Req.xml'

    file_times_access=time.localtime(os.path.getatime(file_name))
    year_access=file_times_access.tm_year
    month_access=file_times_access.tm_mon
    day_access=file_times_access.tm_mday

    hour_access=file_times_access.tm_hour
    minute_access=file_times_access.tm_min
   second_access=file_times_access.tm_sec

    print('file is viewed on:',year_access,'year',month_access,'month',day_access,'day',hour_access,'hour',minute_access,'minute',second_access,'second')

if __name__=='__main__':
    main()

 文件路径使用r,/,\\都可以

file_name='C:\\Temp\\t.txt'

file_name='C:/Temp/t.txt'

posted @ 2018-12-11 14:46  筱筱的春天  阅读(1604)  评论(0编辑  收藏  举报