using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Data; namespace PDF_Office.DataConvert { public class CreateTimeToDate : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (string.IsNullOrEmpty(value.ToString())) { //没有时间得返回系统当前时间 return System.DateTime.Now.ToString("yyyyMMdd"); } else { //部分日期不正常 需要进一步处理 string dateStr = Regex.Match(value.ToString(), "(?<=D\\:)[0-9]+(?=[\\+\\-])").Value; if (string.IsNullOrEmpty(dateStr))//日期不合格时 显示当前系统日期 { dateStr = System.DateTime.Now.ToString("yyyyMMdd"); } return dateStr.Substring(0, 8); } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }