def parse_date_to_ts(date_str):
""" create the timestamp coresponding to a given date string"""
if not date_str:
return None
m = date_matcher.search(date_str)
if not m:
return None
day = m.group(1)
month = m.group(2).capitalize()
year = m.group(3)
hour = m.group(4)
minutes = m.group(5)
if len(day) == 1:
day = "0" + day
if len(hour) == 1:
hour = "0" + hour
if len(minutes) == 1:
minutes = "0" + minutes
date_str = "%s-%s-%s %s:%s" % (day, month, year, hour, minutes)
try:
d = datetime.datetime.strptime( date_str, "%d-%b-%Y %H:%M" )
except:
return None
dtt = d.timetuple() # time.struct_time
ts = int(time.mktime(dtt))
ts -= (3600 * 8)
return ts
评论列表
文章目录