From 2eb841639ea13877f3c32e3716b36eb1c97523c6 Mon Sep 17 00:00:00 2001 From: mxr612 Date: Sat, 14 Jun 2025 04:26:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0format=5Ftime=5Fymd?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增format_time_ymd函数用于将时间格式化为"年.月.日"形式 修改main函数中使用format_time_ymd替代原format_time处理历史记录时间 --- main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 26180f9..2ae1c5d 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,14 @@ def format_time(dt,info): logging.warning(f"[{info}]时间格式错误:{dt}") return dt +def format_time_ymd(dt,info): + try: + return dt.strftime("%Y.%m.%d") + + except: + logging.warning(f"[{info}]时间格式错误:{dt}") + return dt + def to_int(x): try: return int(x) @@ -453,7 +461,7 @@ def main(): logging.error(f"{row['身份证号码']}:{e}") # 保存所有历史记录到Excel文件 - all_history["时间"] = all_history["时间"].apply(lambda x: format_time(x, "历史记录时间")) + all_history["时间"] = all_history["时间"].apply(lambda x: format_time_ymd(x, "历史记录时间")) all_history.to_excel("所有人员历史记录.xlsx", index=False) logging.info("所有人员历史记录已保存到'所有人员历史记录.xlsx'")