python getmtime() 最近修改文件内容的时间

import time
import os


def mm():
    file_name = '1.txt'
    file_times_modified = time.localtime(os.path.getmtime(file_name))
        year_modified = file_times_modified.tm_year
        month_modified = file_times_modified.tm_mon
        day_modified = file_times_modified.tm_mday

        hour_modified = file_times_modified.tm_hour
        minute_modified = file_times_modified.tm_min
        second_modified = file_times_modified.tm_sec
        print('文件的内容最近修改的时间(mtime):  ', year_modified, '年', month_modified, '月', day_modified, '日', '  ', hour_modified, '时',
          minute_modified, '分', second_modified, '秒')


if __name__ == '__main__':
    mm()

 

posted @ 2018-12-11 15:06  筱筱的春天  阅读(2642)  评论(1编辑  收藏  举报