一、从字符串中取出时间
wave_path = r"D:\work\temp\voice_handle\voice_handle_R01\voice\20220323_164711.wav"
match_time = re.match(r"\d{8}_\d{6}", os.path.basename(wave_path))
if match_time:print(match_time.group())# 转为时间格式 strptimevoice_time = datetime.datetime.strptime(match_time.group(), "%Y%m%d_%H%M%S")
二、timedelta方法对当前时间进行加减
加减秒
print(voice_time + datetime.timedelta(seconds=1))
加 一分钟
print (datetime.datetime.now()+datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S")
减 一分钟
print (datetime.datetime.now()+datetime.timedelta(minutes=-1)).strftime("%Y-%m-%d %H:%M:%S")
https://www.cnblogs.com/monogem/p/11170011.html