Home>Article>Backend Development> How to get the creation and modification time of a file
Time representation
The common time representation format is:
Time stamp
Formatted Time string
timestamp (timestamp) Also known as Unix time or POSIX time; it is a time representation that represents The number of milliseconds that have elapsed since January 1, 1970, 0:00:00 GMT, and its value is of type float. However, the related methods of some programming languages return the number of seconds (this is the case with Python). This requires reading the documentation of the method. It should be noted that the timestamp is a difference value, and its value has nothing to do with the time zone.
Case practice:
#endcoding: utf-8 # 获取文件的时间属性 # 用到的知识 # os.getcwd() 方法用于返回当前工作目录 # os.path.getatime(file) 输出文件访问时间 # os.path.getctime(file) 输出文件的创建时间 # os.path.getmtime(file) 输出文件最近修改时间 import time import os def fileTime(file): return [ time.ctime(os.path.getatime(file)), time.ctime(os.path.getmtime(file)), time.ctime(os.path.getctime(file)) ] times = fileTime(os.getcwd()) print(times) print(type(times))
The above is the detailed content of How to get the creation and modification time of a file. For more information, please follow other related articles on the PHP Chinese website!