0

我对此还没有走得太远,我正在尝试检查文件的创建时间,并将日期(仅日、月和年)与今天的日期(再次仅日、月和年)进行比较

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

有人知道我如何转换日期然后检查今天的日期吗?

4

1 回答 1

1
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"
于 2014-02-21T01:21:26.713 回答