在WPF中获得五月和三月的错误月份名称

时间:2019-05-27 15:08:15

标签: c# wpf calendar globalization datetimeformatinfo

hi为什么我输入的月份名称错误?此功能将输入月份的名称

public static System.Globalization.DateTimeFormatInfo GetDateTimeFormatInfoGregorian()
        {
            System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo()
            {
                AbbreviatedDayNames = new string[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" },
                AbbreviatedMonthGenitiveNames = new string[] {
                        "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep",
                        "Oct", "Nov", "Dec", "" },

               AbbreviatedMonthNames = new string[] {
                      "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep",
                        "Oct", "Nov", "Dec", "" },

                CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstDay,
                DateSeparator = "/",

                MonthDayPattern = "dd MMMM",
                MonthGenitiveNames = new string[] {
                       "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep",
                        "Oct", "Nov", "Dec", "" },
                MonthNames = new string[] {
                        "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep",
                        "Oct", "Nov", "Dec", ""  },

            };

            return dtFormat;
        }

这是结果 enter image description here enter image description here

如您所见,五月已更改为 5a19 三月已更改为 3ar
为什么会这样呢?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

由于我无法解释的原因,您的AbbreviatedMonthGenitiveNames由于某些原因而发生冲突...

无论如何,因为您已经定义了此类的值,所以无需使用“ AbbreviatedMonthGenitiveNames”的值声明新数组。

我已经在这里测试了该功能:

System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
foreach(var name in dtFormat.AbbreviatedMonthGenitiveNames)
{
    Console.WriteLine(name);
}

输出为:

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

所以我的意思是删除所有关于该变量的数组函数和声明,因为它们已经被声明了。

经过测试后,尝试解决问题。