检查创建的日期时间并与今天的日期进行比较?(Checking the created time for the date and comparing to todays date?)

编程入门 行业动态 更新时间:2024-10-20 20:40:01
检查创建的日期时间并与今天的日期进行比较?(Checking the created time for the date and comparing to todays date?)

我对此并不是很了解,我正在尝试检查文件的创建时间,只是将日期(只有日,月和年)与今天的日期(再次只有日,月和年)进行比较

import os.path, time import datetime fulldate = time.ctime(os.path.getctime("file.xlsx"))

有谁知道如何转换日期,然后检查今天的日期?

I've not got very far with this, I'm trying to check the creation time of a file and simply compare the date (only the day, month and year) with todays date (again only day, month and year)

import os.path, time import datetime fulldate = time.ctime(os.path.getctime("file.xlsx"))

Anyone know how I can convert the date and then check against todays date?

最满意答案

import os.path, time from datetime import datetime from time import mktime fulldate = time.ctime(os.path.getctime("file.xlsx")) struct = time.strptime(fulldate) filetime = datetime.fromtimestamp(mktime(struct)) filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0) if filetime < datetime.now(): print "The file is quite old" else: print "The file is not so old" import os.path, time from datetime import datetime from time import mktime fulldate = time.ctime(os.path.getctime("file.xlsx")) struct = time.strptime(fulldate) filetime = datetime.fromtimestamp(mktime(struct)) filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0) if filetime < datetime.now(): print "The file is quite old" else: print "The file is not so old"

更多推荐

本文发布于:2023-08-06 08:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   并与   时间   Checking   created

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!