timestamp +2
This commit is contained in:
parent
d52a3eabb1
commit
9d1cfc7bca
BIN
scripts.db
BIN
scripts.db
Binary file not shown.
@ -33,14 +33,26 @@ def process(input_strings: List[str]) -> List[str]:
|
||||
|
||||
elif mode == "text_to_timestamp":
|
||||
try:
|
||||
# 检查是否以 UTC 结尾
|
||||
input_str = input_str.strip()
|
||||
use_utc = input_str.endswith(" UTC")
|
||||
if use_utc:
|
||||
input_str = input_str[:-4].strip() # 移除 " UTC"
|
||||
tz = TIMEZONE_CACHE["UTC"] # 强制使用 UTC 时区
|
||||
|
||||
# 尝试解析三种格式
|
||||
try:
|
||||
dt = datetime.strptime(input_str, "%Y-%m-%d %H:%M:%S")
|
||||
except ValueError:
|
||||
dt = datetime.strptime(input_str, "%Y年%m月%d日 %H:%M:%S")
|
||||
try:
|
||||
dt = datetime.strptime(input_str, "%Y年%m月%d日 %H:%M:%S")
|
||||
except ValueError:
|
||||
# 解析新格式:MMM-DD-YYYY HH:MM:SS AM/PM
|
||||
dt = datetime.strptime(input_str, "%b-%d-%Y %I:%M:%S %p")
|
||||
dt = tz.localize(dt)
|
||||
return [str(int(dt.timestamp()))]
|
||||
except ValueError:
|
||||
return ["错误:请输入有效的日期格式(YYYY-MM-DD HH:MM:SS 或 YYYY年MM月DD日 HH:MM:SS)"]
|
||||
return ["错误:请输入有效的日期格式(YYYY-MM-DD HH:MM:SS 或 YYYY年MM月DD日 HH:MM:SS 或 MMM-DD-YYYY HH:MM:SS AM/PM)"]
|
||||
|
||||
return ["错误:无效的转换模式"]
|
||||
except Exception as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user