DateTimeExtension.cs 1.2 KB

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