32 lines
975 B
C#
32 lines
975 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
|
|
namespace MainShell.Converter
|
|
{
|
|
public class DateTimeToStringConverter : IValueConverter
|
|
{
|
|
public string Format { get; set; } = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null) return string.Empty;
|
|
if (!(value is DateTime dt)) return string.Empty;
|
|
if (dt == DateTime.MinValue) return string.Empty;
|
|
|
|
// parameter 优先用于临时格式覆盖
|
|
var fmt = parameter as string ?? Format;
|
|
return dt.ToString(fmt, culture);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|