DateTimeExtension.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using Core.Util.Common;
  3. namespace Core.Util.Extension
  4. {
  5. /// <summary>
  6. /// 时间帮助扩展类
  7. /// </summary>
  8. public static class DateTimeExtension
  9. {
  10. private static readonly DateTime MinDate = new DateTime(1970, 1, 1);
  11. private static readonly DateTime MaxDate = new DateTime(9999, 12, 31, 23, 59, 59, 999);
  12. /// <summary>
  13. /// 当前时间是否有效范围之内
  14. /// </summary>
  15. /// <param name="target"></param>
  16. /// <returns></returns>
  17. public static bool IsValid(this DateTime target)
  18. {
  19. return (target >= MinDate) && (target <= MaxDate);
  20. }
  21. /// <summary>时间日期转为yyyy-MM-dd HH:mm:ss完整字符串,支持指定最小时间的字符串</summary>
  22. public static string ToFullString(this DateTime value, string emptyValue = null)
  23. {
  24. return new DefaultConvert().ToFullString(value, emptyValue);
  25. }
  26. /// <summary>时间日期转为指定格式字符串</summary>
  27. public static string ToString(this DateTime value, string format, string emptyValue)
  28. {
  29. return new DefaultConvert().ToString(value, format, emptyValue);
  30. }
  31. }
  32. }