Python学习之datetime

image

 

import os, datetime

from datetime import date
from pathlib import Path

file_path = "C:\\Users\\mengchen.shao\\Desktop\\BET"

path = Path(file_path)

for file in path.iterdir():
creation_time = os.path.getctime(file)
update_time = os.path.getmtime(file)
cre_date = datetime.datetime.fromtimestamp(creation_time).date()
upd_date = datetime.datetime.fromtimestamp(update_time).date()
today = date.today()
print(f"{file}文件的创建时间:{(today - cre_date).days}")
print(f"{file}文件的更新时间:{(today - upd_date).days}")
posted @ 2025-12-29 15:03  狗狗听话  阅读(5)  评论(0)    收藏  举报