gpt4 book ai didi

c# - 如何在 IValueConverter 中设置 DateTime 格式并返回字符串值?

转载 作者:行者123 更新时间:2023-11-30 15:38:16 25 4
gpt4 key购买 nike

我想要在 IValueConverter 中使用特定格式并返回一个字符串。像 "MMMyyyy" 我怎样才能得到这个?

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString();
}
return null;
}

最佳答案

请尝试以下

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString("MMMyyyy");
}
return null;
}

关于c# - 如何在 IValueConverter 中设置 DateTime 格式并返回字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com