更改日期选择器文本:大写月份

时间:2012-08-19 16:57:26

标签: c# datepicker

我想通过上限包装当月的第一个字母来更改日期选择器。

目前我在线程中使用 set culture info 并在那里指定格式,但对于我的文化,月份总是全部小写:

CultureInfo ci = new CultureInfo("es-MX");
ci.DateTimeFormat.ShortDatePattern = "ddd dd/MMM/yyyy";
Thread.CurrentThread.CurrentCulture = ci;

显示:

Dom 19/ago/2012

我想:

Dom 19/Ago/2012

我该如何改变?

2 个答案:

答案 0 :(得分:5)

指定AbbreviatedMonthGenitiveNamesAbbreviatedMonthNames以及ShortDatePattern就可以了。

Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX")
{
    DateTimeFormat = new DateTimeFormatInfo
    {
        AbbreviatedMonthGenitiveNames = new string[] { "Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic", string.Empty },
        AbbreviatedMonthNames         = new string[] { "Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic", string.Empty },
        ShortDatePattern = "ddd dd/MMM/yyyy"
    }
};

收率:

enter image description here

编辑:

我必须补充:

...
AbbreviatedDayNames = new string[] { "Dom",  "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"},

答案 1 :(得分:2)

您可以使用CultureAndRegionInfoBuilder class复制现有文化并仅更改月份名称。然后,您随后在应用程序中使用该文化,而不是您现在使用的CultureInfo

但请注意,CultureAndRegionInfoBuilder汇编中sysglobl.dll位于which you'll need to import