日期时间转换器 WPF [英] datetime converter WPF
本文介绍了日期时间转换器 WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个转换器,我可以在从 DataPicker 中选择日期后获取当前时间.在字符串日期中,我正在获取从 DatePicker 中选择的值,但我似乎不能只获取日期.进入 Value 属性的格式是 9/24/2013 12:00:00 我希望它是 9/24/2013
I have this converter that i made to get the current time once the date is selected from the DataPicker. In string Date i am getting the value that was selected from the DatePicker, but i cant seem to only get the date. The format that is coming into the Value property is 9/24/2013 12:00:00 I would like it to be 9/24/2013
我得到的错误是错误 122 没有重载方法 'ToString' 需要 1 个参数"
the error i am getting is "Error 122 No overload for method 'ToString' takes 1 argument"
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime)
{
string date = value.ToString("d/M/yyyy");
return (date);
}
return string.Empty;
}
推荐答案
您需要先将其强制转换为 DateTime:
You need to cast it to DateTime first:
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (value is DateTime)
{
DateTime test = (DateTime) value;
string date = test.ToString("d/M/yyyy");
return date;
}
return string.Empty;
}
这篇关于日期时间转换器 WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文