python如何判断文件大小_如何在Python中查看文件是否超过3个月?

我很想知道在 Python中操纵时间.我可以使用os.path.getmtime()函数获取文件的(上次修改)年龄:

import os.path, time

os.path.getmtime(oldLoc)

我需要运行某种测试来查看这个时间是否在过去三个月内,但我对Python中所有可用的时间选项感到困惑.

谁能提供任何见解?亲切的问候.

如果您需要准确的天数,可以将日历模块与日期时间结合使用,例如,

import calendar

import datetime

def total_number_of_days(number_of_months=3):

c = calendar.Calendar()

d = datetime.datetime.now()

total = 0

for offset in range(0, number_of_months):

current_month = d.month - offset

while current_month <= 0:

current_month = 12 + current_month

days_in_month = len( filter(lambda x: x != 0, c.itermonthdays(d.year, current_month)))

total = total + days_in_month

return total

然后将total_number_of_days()的结果提供给其他人为日期算术提供的代码.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值