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'

相关文章:

  • 2021-09-19
  • 2021-11-26
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2022-01-04
  • 2022-12-23
  • 2022-02-25
  • 2021-11-30
  • 2021-12-19
相关资源
相似解决方案