DateTime类增加了两个扩展ToDate返回yyyy-MM-dd日期格式字符串,ToTime返回HH:mm:ss时间格式字符串。

This commit is contained in:
falcon 2023-04-19 16:36:03 +08:00
parent deea9c1457
commit 58567e5f8c

View File

@ -97,6 +97,19 @@ namespace Falcon.SugarApi
/// <returns>yyyyMMdd格式时间</returns> /// <returns>yyyyMMdd格式时间</returns>
public static string ToyyyyMMddHHmmss(this DateTime date) => date.ToString("yyyyMMddHHmmss"); public static string ToyyyyMMddHHmmss(this DateTime date) => date.ToString("yyyyMMddHHmmss");
/// <summary>
/// 返回日期的年月日字符串格式yyyy-MM-dd
/// </summary>
/// <param name="date">时间</param>
/// <returns>格式化日期字符串</returns>
public static string ToDate(this DateTime date) => date.ToString("yyyy-MM-dd");
/// <summary>
/// 返回时间的小时分秒字符串格式HH:mm:ss
/// </summary>
/// <param name="date">时间</param>
/// <returns>格式化时间字符串</returns>
public static string ToTime(this DateTime date) => date.ToString("HH:mm:ss");
#endregion #endregion
} }