优化日期类处理

This commit is contained in:
2024-06-24 14:24:48 +08:00
parent 7820b4b762
commit 6e77f20c1e

View File

@@ -27,8 +27,8 @@ def handle_date(string):
string = string.replace("", "-").replace("", "-").replace("", "").replace("/", "-").replace(".", "-") string = string.replace("", "-").replace("", "-").replace("", "").replace("/", "-").replace(".", "-")
string = re.sub(r'[^0-9-]', '', string) string = re.sub(r'[^0-9-]', '', string)
string = string.strip("-")
if "-" in string: if "-" in string:
string = string.strip("-")
dash_count = string.count("-") dash_count = string.count("-")
if dash_count > 2: if dash_count > 2:
third_dash_index = string.find("-", string.find("-", string.find("-") + 1) + 1) third_dash_index = string.find("-", string.find("-", string.find("-") + 1) + 1)
@@ -118,3 +118,7 @@ def handle_original_data(string):
return "" return ""
# 防止过长存入数据库失败 # 防止过长存入数据库失败
return string[:255] return string[:255]
if __name__ == '__main__':
print(handle_date("2024年"))