From dfb04f742c79131549bccc848035538f4aca57e6 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Sun, 9 Oct 2022 11:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAyyyyMMdd=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi.Test/DateTimeExtendTest.cs | 10 ++++++++++ Falcon.SugarApi/DateTimeExtend.cs | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Falcon.SugarApi.Test/DateTimeExtendTest.cs b/Falcon.SugarApi.Test/DateTimeExtendTest.cs index baa30b9..311cc09 100644 --- a/Falcon.SugarApi.Test/DateTimeExtendTest.cs +++ b/Falcon.SugarApi.Test/DateTimeExtendTest.cs @@ -81,5 +81,15 @@ namespace Falcon.SugarApi.Test Assert.IsTrue(r.Second == 0); } + + /// + /// 时间格式转换测试 + /// + [TestMethod] + public void DateToFormatTest() { + var d = new DateTime(2022, 1, 4, 2, 40, 25); + var s = d.ToyyyyMMdd(); + Assert.IsTrue(s == "20220104"); + } } } diff --git a/Falcon.SugarApi/DateTimeExtend.cs b/Falcon.SugarApi/DateTimeExtend.cs index 7ad4604..4aa4bee 100644 --- a/Falcon.SugarApi/DateTimeExtend.cs +++ b/Falcon.SugarApi/DateTimeExtend.cs @@ -9,6 +9,7 @@ namespace Falcon.SugarApi /// public static class DateTimeExtend { + #region 获取某个时间 /// /// 获取日期在某个时间段内的某一天 /// @@ -78,6 +79,18 @@ namespace Falcon.SugarApi public static Calendar GetDefaultCalendar(this DateTime dateTime) { return CultureInfo.CurrentCulture.Calendar; } + + #endregion + + #region 获取某个时间格式 + /// + /// 获取时间的yyyyMMdd表示形式 + /// + /// 时间 + /// yyyyMMdd格式时间 + public static string ToyyyyMMdd(this DateTime date) => date.ToString("yyyyMMdd"); + + #endregion } ///