From a8c13892dcf92a2285d14e78d9b38f24136eb3d9 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Thu, 27 Oct 2022 10:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=98=AF=E5=90=A6=E4=B8=BA=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi/StringExtend.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Falcon.SugarApi/StringExtend.cs b/Falcon.SugarApi/StringExtend.cs index ec0b773..e38a5c5 100644 --- a/Falcon.SugarApi/StringExtend.cs +++ b/Falcon.SugarApi/StringExtend.cs @@ -72,5 +72,22 @@ namespace Falcon.SugarApi return false; } } + + /// + /// 返回字符串是否为指定格式的日期时间格式 + /// + /// 给定字符串 + /// 日期时间格式 + /// 是True,否False + /// 参数为空 + public static bool IsDateFormat(this string str, string dateFormat) { + if (str.IsNullOrEmpty()) { + throw new ArgumentNullException(nameof(str)); + } + if (dateFormat.IsNullOrEmpty()) { + throw new ArgumentNullException(nameof(dateFormat)); + } + return str.TryToDateTime(dateFormat, out var _); + } } -} +} \ No newline at end of file