【发布时间】:2012-07-20 23:54:21
【问题描述】:
我已经浏览 Python 指南和一些搜索机几个小时了,但我真的找不到我的问题的答案。
我正在编写一个开关,其中只有某些文件在给定日期之后被修改时被选择在 file_list (list[]) 中。
在我的循环中,我执行以下代码来获取它的微时间:
file_time = os.path.getmtime(path + file_name)
这给我一个很好的微时间,像这样:1342715246.0
现在我想比较那个时间是否在我放弃的某个日期时间之后。因此,出于测试目的,我使用了 1790:01:01 00:00:00。
# Preset (outside the class/object)
start_time = '1970-01-01 00:00:00'
start_time = datetime.datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S')
start_time = start_time.strftime("%Y-%m-%d %H:%M:%S")
# In my Method this check makes sure I only append files to the list
# that are modified after the given date
if file_time > self.start_time:
file_list.append(file_name)
当然这不起作用,哈哈:P。我的目标是从自定义日期制作微时间格式。我只能在网上找到从当前日期开始制作微时间格式的 ClassMethods。
【问题讨论】: