CreateTimeToDate.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. namespace PDF_Office.DataConvert
  10. {
  11. public class CreateTimeToDate : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (string.IsNullOrEmpty(value.ToString()))
  16. {
  17. //没有时间得返回系统当前时间
  18. return System.DateTime.Now.ToString("yyyyMMdd");
  19. }
  20. else
  21. {
  22. //部分日期不正常 需要进一步处理
  23. string dateStr = Regex.Match(value.ToString(), "(?<=D\\:)[0-9]+(?=[\\+\\-])").Value;
  24. if (string.IsNullOrEmpty(dateStr))//日期不合格时 显示当前系统日期
  25. {
  26. dateStr = System.DateTime.Now.ToString("yyyyMMdd");
  27. }
  28. return dateStr.Substring(0, 8);
  29. }
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. }
  36. }