Python3鍩虹 getatime getctime getmtime 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3鍩虹 getatime getctime getmtime 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/tin' title='tin'>tin
涓€浠朵簨 bsp 浜や簰 鏂规硶 tail python hang 绉疮?
- python : 3.7.0
- OS : Ubuntu 18.04.1 LTS
- IDE : PyCharm 2018.2.4
- conda : 4.5.11
- type setting : Markdown
?
code
"""
@Author : 琛屽垵蹇?@Date : 18-10-2
@Blog : www.cnblogs.com/xingchuxin
@GitHub : github.com/GratefulHeartCoder
"""
import time
import os
def main():
file_name = 鈥?.txt鈥?
# 鏂囦欢鐨勬渶杩戣闂椂闂? 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(鈥樻枃浠剁殑鏈€杩戣闂椂闂?atime): 鈥? year_access, 鈥樺勾鈥? month_access, 鈥樻湀鈥? day_access, 鈥樻棩鈥? 鈥? 鈥? hour_access, 鈥樻椂鈥?
minute_access, 鈥樺垎鈥? second_access, 鈥樼鈥?
# 鏂囦欢灞炴€ф渶杩戜慨鏀圭殑鏃堕棿
file_times_create = time.localtime(os.path.getctime(file_name))
year_create = file_times_create.tm_year
month_create = file_times_create.tm_mon
day_create = file_times_create.tm_mday
hour_create = file_times_create.tm_hour
minute_create = file_times_create.tm_min
second_create = file_times_create.tm_sec
print(鈥樻枃浠跺睘鎬ф渶杩戜慨鏀圭殑鏃堕棿(ctime): 鈥? year_create, 鈥樺勾鈥? month_create, 鈥樻湀鈥? day_create, 鈥樻棩鈥? 鈥? 鈥? hour_create, 鈥樻椂鈥? minute_create,
鈥樺垎鈥? second_create, 鈥樼鈥?
# 鏂囦欢鐨勫唴瀹规渶杩戜慨鏀圭殑鏃堕棿
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__鈥?
main()
?
result
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/base/demo.py
鏂囦欢鐨勬渶杩戣闂椂闂?atime): 2018 骞?10 鏈?2 鏃? 12 鏃?25 鍒?26 绉?鏂囦欢灞炴€ф渶杩戜慨鏀圭殑鏃堕棿(ctime): 2018 骞?10 鏈?2 鏃? 12 鏃?33 鍒?13 绉?鏂囦欢鐨勫唴瀹规渶杩戜慨鏀圭殑鏃堕棿(mtime): 2018 骞?10 鏈?2 鏃? 12 鏃?25 鍒?8 绉?
Process finished with exit code 0
鍦╰erminal涓獙璇?/p>
[email protected]:~/PycharmProjects/base$ stat 1.txt
鏂囦欢锛?.txt
澶у皬锛?3 鍧楋細8 IO 鍧楋細4096 鏅€氭枃浠?璁惧锛?08h/2056d Inode锛?29035 纭摼鎺ワ細1
鏉冮檺锛?0777/-rwxrwxrwx) Uid锛? 1000/ coder) Gid锛? 1000/ coder)
鏈€杩戣闂細2018-10-02 12:25:26.445044634 +0800
鏈€杩戞洿鏀癸細2018-10-02 12:25:08.688137355 +0800
鏈€杩戞敼鍔細2018-10-02 12:33:13.972664234 +0800
鍒涘缓鏃堕棿锛?
[email protected]:~/PycharmProjects/base$
?
more knowledge
- linux涓紝鏂囦欢鐨勪笁涓椂闂村垎鍒槸锛欰ccess銆丮odify鍜孋hange[1]銆?娉ㄦ剰锛氭病鏈塁reate)
- ext4鏂囦欢绯荤粺涓湁鏂囦欢鍒涘缓鏃堕棿锛屽叾瀛楁涓篶rtime[2]銆?浣嗘槸锛屼娇鐢╯tat鍛戒护鍚庡彂鐜?-> 鍒涘缓鏃堕棿锛?锛?/li>
- 鍐呮牳宸茬粡閫氳繃 4.11 鐗堟湰寮曞叆鐨?statx 绯荤粺璋冪敤鏀寔鑾峰彇鍒涘缓鏃堕棿浜嗐€?sup>[3]
鍦ㄥ唴鏍告簮鐮佹爲涓湁鐜版垚鐨?samples/statx/test-statx.c[3]
缂栬瘧锛歡cc -O2 -o statx test-statx.c[3]
?
reference
- [1] https://blog.csdn.net/qq_31828515/article/details/62886112
- [2] https://blog.csdn.net/k346k346/article/details/78668100
- [3] https://blog.lilydjwg.me/2018/7/11/get-file-birth-time-in-linux.213101.html
?
resource
- [鏂囨。] https://docs.python.org/3/
- [瑙勮寖] https://www.python.org/dev/peps/pep-0008/
- [瑙勮寖] https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/
- [婧愮爜] https://www.python.org/downloads/source/
- [ PEP ] https://www.python.org/dev/peps/
- [骞冲彴] https://www.cnblogs.com/
?
Python鍏锋湁寮€婧愩€佽法骞冲彴銆佽В閲婂瀷銆佷氦浜掑紡绛夌壒鎬э紝鍊煎緱瀛︿範銆?br> Python鐨勮璁″摬瀛︼細浼橀泤锛屾槑纭紝绠€鍗曘€傛彁鍊$敤涓€绉嶆柟娉曪紝鏈€濂芥槸鍙湁涓€绉嶆柟娉曟潵鍋氫竴浠朵簨銆?br> 浠g爜鐨勪功鍐欒閬靛畧瑙勮寖锛岃繖鏍锋湁鍔╀簬娌熼€氬拰鐞嗚В銆?br> 姣忕璇█閮芥湁鐙壒鐨勬€濇兂锛屽垵瀛﹁€呴渶瑕佽浆鍙樻€濈淮銆佽笍瀹炶返琛屻€佸潥鎸佺Н绱€?/p>
以上是关于Python3鍩虹 getatime getctime getmtime 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿的主要内容,如果未能解决你的问题,请参考以下文章