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 } ///