import os import time print(os.path.abspath('logger.log')) path = os.path.abspath('logger.log') print(time.ctime(os.path.getatime(path))) print(type(time.ctime(os.path.getatime(path)))) ti = os.path.getatime(path) print(type(ti)) print(time.localtime(ti)) print(time.strftime("%Y-%m-%d %X", time.localtime(ti)))
结果: C:\DELL\Python\20200225_模块\logger.log Tue Feb 25 12:34:58 2020 <class 'str'> <class 'float'> time.struct_time(tm_year=2020, tm_mon=2, tm_mday=25, tm_hour=12, tm_min=34, tm_sec=58, tm_wday=1, tm_yday=56, tm_isdst=0) 2020-02-25 12:34:58