删除 test.py

main
wangsiyuan 2023-09-01 17:54:02 +08:00
parent 2b6092e1e6
commit fe03bf15df
1 changed files with 0 additions and 22 deletions

22
test.py
View File

@ -1,22 +0,0 @@
from datetime import datetime
def format_time_string(input_time_str):
try:
# 解析时区时间字符串为datetime对象
dt_object = datetime.strptime(input_time_str, "%a %b %d %H:%M:%S %Z %Y")
# 将datetime对象重新格式化为所需的字符串格式
formatted_time_str = dt_object.strftime("%Y-%m-%d %H:%M:%S")
return formatted_time_str
except ValueError as e:
print("Error: Invalid time format.")
return None
# 测试函数
input_time_str = "Mon Aug 7 09:33:39 BST 2023"
formatted_time = format_time_string(input_time_str)
if formatted_time is not None:
print(formatted_time)