我想从下面的值中提取年月日小时分钟。
import os, time, os.path, datetime
date_of_created = time.ctime(os.path.getctime(folderName))
date_of_modi = time.ctime(os.path.getmtime(folderName))
现在我只能像下面这样 '2019 年 12 月 26 日星期四 19:21:37' 但我想单独获取值 2019//12 月(我可以将其作为 int 获取吗?)//26 每个
我想从 date_of_created 和 date_of_modi 中提取每年月日每次的最小值 我能拿到吗?在Python中?
最佳答案
您可以将字符串转换为日期时间对象:
from datetime import datetime
date_of_created = datetime.strptime(time.ctime(os.path.getctime(folderName)), "%a %b %d %H:%M:%S %Y") # Convert string to date format
print("Date created year: {} , month: {} , day: {}".format(str(date_of_created.year),str(date_of_created.month),str(date_of_created.day)))
关于python - 从 Python 中的 getctime 、 getmtime 中提取每年、月、日、年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60145251/