增加时间转换为yyyyMMddHHmmss格式扩展方法

This commit is contained in:
falcon 2022-10-09 11:24:06 +08:00
parent 0d7cbbe70c
commit 346ebc47c3
2 changed files with 9 additions and 0 deletions

View File

@ -90,6 +90,8 @@ namespace Falcon.SugarApi.Test
var d = new DateTime(2022, 1, 4, 2, 40, 25); var d = new DateTime(2022, 1, 4, 2, 40, 25);
var s = d.ToyyyyMMdd(); var s = d.ToyyyyMMdd();
Assert.IsTrue(s == "20220104"); Assert.IsTrue(s == "20220104");
s = d.ToyyyyMMddHHmmss();
Assert.IsTrue(s == "20220104024025");
} }
} }
} }

View File

@ -90,6 +90,13 @@ namespace Falcon.SugarApi
/// <returns>yyyyMMdd格式时间</returns> /// <returns>yyyyMMdd格式时间</returns>
public static string ToyyyyMMdd(this DateTime date) => date.ToString("yyyyMMdd"); public static string ToyyyyMMdd(this DateTime date) => date.ToString("yyyyMMdd");
/// <summary>
/// 获取时间的yyyyMMddHHmmss表示形式
/// </summary>
/// <param name="date">时间</param>
/// <returns>yyyyMMdd格式时间</returns>
public static string ToyyyyMMddHHmmss(this DateTime date) => date.ToString("yyyyMMddHHmmss");
#endregion #endregion
} }