You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
919 B

#!/usr/bin/env python
# encoding: utf-8
import re
import datetime
def time_fix(time_string):
now_time = datetime.datetime.now()
if '分钟前' in time_string:
minutes = re.search(r'^(\d+)分钟', time_string).group(1)
created_at = now_time - datetime.timedelta(minutes=int(minutes))
return created_at.strftime('%Y-%m-%d %H:%M:%S')
if '小时前' in time_string:
minutes = re.search(r'^(\d+)小时', time_string).group(1)
created_at = now_time - datetime.timedelta(hours=int(minutes))
return created_at.strftime('%Y-%m-%d %H:%M:%S')
if '今天' in time_string:
return time_string.replace('今天', now_time.strftime('%Y-%m-%d'))
if '' in time_string:
time_string = time_string.replace('', '-').replace('', '')
time_string = str(now_time.year) + '-' + time_string
return time_string
return time_string