增加时间转换为yyyyMMdd格式的扩展方法。
This commit is contained in:
parent
4eba08e692
commit
dfb04f742c
|
@ -81,5 +81,15 @@ namespace Falcon.SugarApi.Test
|
||||||
Assert.IsTrue(r.Second == 0);
|
Assert.IsTrue(r.Second == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间格式转换测试
|
||||||
|
/// </summary>
|
||||||
|
[TestMethod]
|
||||||
|
public void DateToFormatTest() {
|
||||||
|
var d = new DateTime(2022, 1, 4, 2, 40, 25);
|
||||||
|
var s = d.ToyyyyMMdd();
|
||||||
|
Assert.IsTrue(s == "20220104");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace Falcon.SugarApi
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DateTimeExtend
|
public static class DateTimeExtend
|
||||||
{
|
{
|
||||||
|
#region 获取某个时间
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取日期在某个时间段内的某一天
|
/// 获取日期在某个时间段内的某一天
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -78,6 +79,18 @@ namespace Falcon.SugarApi
|
||||||
public static Calendar GetDefaultCalendar(this DateTime dateTime) {
|
public static Calendar GetDefaultCalendar(this DateTime dateTime) {
|
||||||
return CultureInfo.CurrentCulture.Calendar;
|
return CultureInfo.CurrentCulture.Calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 获取某个时间格式
|
||||||
|
/// <summary>
|
||||||
|
/// 获取时间的yyyyMMdd表示形式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="date">时间</param>
|
||||||
|
/// <returns>yyyyMMdd格式时间</returns>
|
||||||
|
public static string ToyyyyMMdd(this DateTime date) => date.ToString("yyyyMMdd");
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user