If statement 如何在两个时间戳之间获取数据

If statement 如何在两个时间戳之间获取数据,if-statement,time,system,do-while,If Statement,Time,System,Do While,我有一个时间戳,比如2015-08-31-21.43.47.986782,我需要获取这个时间戳和当前系统时间戳之间捕获的所有数据。我怎么做?我需要去任何类型的条件吗?如果是,请详细说明我将使用Python和正则表达式。如果您的数据是 2015-08-31-21.43.47.986782 zero data data the data some thing else and some more data one data data the data some thing else and som

我有一个时间戳,比如2015-08-31-21.43.47.986782,我需要获取这个时间戳和当前系统时间戳之间捕获的所有数据。我怎么做?我需要去任何类型的条件吗?如果是,请详细说明

我将使用Python和正则表达式。如果您的数据是

2015-08-31-21.43.47.986782 zero data data the data some thing else and 
some more data
one data data the data some thing else and some more data
two data data the data some thing else and some more data
three data data the data some thing else and some more data
four data data the data some thing else and some more data
2015-08-31-22.43.47.986782 zero this is some other datathis is some other datathis is some other data
one this is some other data
two this is some other data
three this is some other data
four this is some other data
five this is some other data
2015-08-31-23.43.47.986782 zero This data is completely new
one This data is completely new
two This data is completely new
three This data is completely new
也就是说,如果每个日期之间有多行,则必须考虑每个日期的累积数据。下面的代码

#!/usr/bin/env python
import re
fp          = open('thefilename.log')
md          = None
for thisRec in fp:
    # get rid of the newline
    thisRec = thisRec.rstrip('\n')
    # Format EG; 2015-08-31-21.43.47.986782
    myMatch = re.search(r'(?P<date>201\d-\d{2}-\d{2}-\d{2}.\d{2}.\d{2}.\d{6})(?P<msg2>.*)', \
        thisRec)

    if myMatch:
        if md:
            # A date has been found, so terminate the data
            theData = md['msg2'] 
            # and start again with a new date
            newDate = md['date']

            # print the data found
            print theData
            print '================================='
            print 'New date: ' + newDate
        # end if 
        # and start collecting data again
        md  = myMatch.groupdict()
    else:
        # a date has not been found, append the data with a new line
        if md:  
            md['msg2']  += '\n' + thisRec
        # end if
    # end if

# next thisRec
# print the last msg
print md['msg2']
print '#####################END OF REPORT#################'

fp.close()

不确定strftime格式,但类似于这样。根据您希望日志在之前还是之后显示,您可以将其放入if myMatch:或else:

此处没有足够的信息。您请求的数据是持续时间还是开始和结束日期?需要数据库查询吗?或者别的什么。我需要通过shell脚本来完成。事实上,我有一个时间戳,直到一些记录被捕获为止。现在我必须获取在该时间戳和当前系统时间戳之间捕获的数据。
import datetime.datetime as dt
...
mynow = dt.now()
if md['date'] == mynow.strftime('%Y-%m-%d-%H.%M.%S.%f'):
    break
# end if