wpf 如何获得特定于文化的短日期字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11665696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a culture specific short date string?
提问by Sachin
I want short date with culture format. I got date with the culture but also want only date, not a time. I am using IValueConverterfor that.
我想要文化格式的短日期。我与文化约会,但也只想要约会,而不是时间。我正在使用IValueConverter它。
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString(culture);
}
return null;
}
回答by Arif Eqbal
This will give you based on current culture, if you want a specific culture that can be done too...
如果您想要一种也可以完成的特定文化,这将为您提供基于当前文化的信息...
string format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
String Date = DateTime.Now.ToString(format);
回答by Sachin
Your answer is also right but I found the solution thanks.
您的回答也是正确的,但我找到了解决方案,谢谢。
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString(culture.DateTimeFormat.ShortDatePattern, culture);
}
return null;
}

