我正在尝试从字符串中提取日期和时间,建立该字符串与当前日期和时间之间的增量。我尝试将正则表达式输出从列表转换为字符串,它显示为 type=string 但格式如下 - ('18:06:39', 'Jan 30 2020')。
import re
from datetime import datetime, timedelta, date
string = 'configuration change at 18:06:39 EET Thu Jan 30 2020 by netbrain'
chg_date = re.findall(r"(\d{2}:\d{2}:\d{2}) \w+ \w+ (\w{3} \d{2} \d{4})", string)
chg_date_str = ''.join(map(str, chg_date))
now = datetime.now()
now_format = now.strftime("%H:%M:%S, %b %d %y")
time_difference = now_format - chg_date_str
print(chg_date_str)
print(time_difference)
我收到以下错误。
Traceback (most recent call last):
File "C:/Users/MattSherman/Desktop/Python/y.py", line 15, in <module>
time_difference = now_format - chg_date_str
TypeError: unsupported operand type(s) for -: 'str' and 'str'
莫回无
qq_遁去的一_1
猛跑小猪
相关分类