如何比较python中的历元时间和当前时间?

如何比较python中的历元时间和当前时间?,python,time,Python,Time,我想将创建的时间文件的输出与实际时间进行比较 import os.path, time print "created: %s" % time.ctime(os.path.getctime(file)) #Tue Apr 8 09:34:33 2014 print "created: %s" % os.path.getctime(file) #1396965031 有可能做这样的事情: if os.path.getctime(file) < 100 #eg file older than

我想将创建的时间文件的输出与实际时间进行比较

import os.path, time
print "created: %s" % time.ctime(os.path.getctime(file))
#Tue Apr 8 09:34:33 2014

print "created: %s" % os.path.getctime(file)
#1396965031
有可能做这样的事情:

if os.path.getctime(file) < 100 #eg file older than 100 seconds
do something
如果os.path.getctime(文件)<100#例如文件超过100秒
做点什么

谢谢

您应该可以这样做:

>>> created = os.path.getctime(filename)
>>> now = time.time()
>>> if now - created > 100:
    print "Haha"
或简而言之:

>>> if time.time() - os.path.getctime(filename) > 100:
    print "Haha"
在这两种情况下,您都需要将文件的创建时间与当前时间进行比较。此外,file是Python中的一个关键字。因此,尽量不要将其用作变量名


希望这篇文章能有所帮助

你应该能够做到:

>>> created = os.path.getctime(filename)
>>> now = time.time()
>>> if now - created > 100:
    print "Haha"
或简而言之:

>>> if time.time() - os.path.getctime(filename) > 100:
    print "Haha"
在这两种情况下,您都需要将文件的创建时间与当前时间进行比较。此外,file是Python中的一个关键字。因此,尽量不要将其用作变量名


希望这篇文章能有所帮助

你应该能够做到:

>>> created = os.path.getctime(filename)
>>> now = time.time()
>>> if now - created > 100:
    print "Haha"
或简而言之:

>>> if time.time() - os.path.getctime(filename) > 100:
    print "Haha"
在这两种情况下,您都需要将文件的创建时间与当前时间进行比较。此外,file是Python中的一个关键字。因此,尽量不要将其用作变量名


希望这篇文章能有所帮助

你应该能够做到:

>>> created = os.path.getctime(filename)
>>> now = time.time()
>>> if now - created > 100:
    print "Haha"
或简而言之:

>>> if time.time() - os.path.getctime(filename) > 100:
    print "Haha"
在这两种情况下,您都需要将文件的创建时间与当前时间进行比较。此外,file是Python中的一个关键字。因此,尽量不要将其用作变量名


希望这篇文章能有所帮助

将其保存在变量中以供将来参考将其保存在变量中以供将来参考将其保存在变量中以供将来参考将其保存在变量中以供将来参考