From 1f8a271cb68f9b4c99fdd6b880f302ff03988354 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 15 Jul 2024 08:41:08 +0800 Subject: [PATCH] improve date get from filename --- plugins/Common.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/Common.php b/plugins/Common.php index ea2e269..55862bb 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -585,19 +585,19 @@ Class Common { $date = ''; try { - preg_match('/^.*(\d{13}).*$/', $str, $matches); //单位毫秒的时间戳 - if (empty($matches[1])) { //再尝试单位秒的时间戳 + preg_match('/^.*(\d{4}[012]{2}\d{2}).*$/', $str, $matches); //尝试Y-m-d格式的日期 + if (empty($matches[1])) { //再尝试单位秒的时间戳 preg_match('/^.*(\d{10}).*$/', $str, $matches); - if (empty($matches[1])) { //再尝试Y-m-d格式的日期 - preg_match('/^.*(\d{4}[012]{2}\d{2}).*$/', $str, $matches); + if (empty($matches[1])) { + preg_match('/^.*(\d{13}).*$/', $str, $matches); //单位毫秒的时间戳 if (!empty($matches[1])) { - $date = date('Y-m-d', strtotime($matches[1])); + $date = date('Y-m-d', (int)$matches[1] / 1000); } }else { $date = date('Y-m-d', (int)$matches[1]); } }else { - $date = date('Y-m-d', (int)$matches[1] / 1000); + $date = date('Y-m-d', strtotime($matches[1])); } }catch(Exception $e) {}