Home  >  Article  >  Backend Development  >  How to get the creation and modification time of a file

How to get the creation and modification time of a file

anonymity
anonymityOriginal
2019-05-25 09:46:264483browse

Time representation

The common time representation format is:

Time stamp

Formatted Time string

How to get the creation and modification time of a file

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn