C#中是否有内置的月份名称变量

[英]Are there built-in Month name declensions in C#


I'm wondering if there's any built-in functionality in .NET for declining dates in languages that support noun declensions, (ie. In Russian the month name is февраль, but if I wanted to say the date or say that something is due by, I'd use the form февраля). I made my own version, which works for this case, but I will need to expand to to other cases, and other languages, which will have their own declensions for dates.

我想知道.NET中是否有任何内置功能可以缩减支持名词变量的语言中的日期(例如,在俄语中,月份名称是февраль,但如果我想说日期或说某事是由于,我使用февраля表格。我制作了自己的版本,适用于本案例,但我需要扩展到其他案例和其他语言,这些语言将有自己的日期变量。

Is this functionality built-in, or available in an external library? Thank you for any help.

此功能是内置的,还是在外部库中可用?感谢您的任何帮助。

I've provided my function for the Russian genitive case, if my explanation wasn't clear.

如果我的解释不清楚,我已经为俄罗斯的属格案例提供了我的功能。

public static string DeclineMonth(this DateTime time)
{
    var month = time.ToString("MMMM");
    if (month.Last() == 'ь')
        return month.Replace('ь', 'я');
    else
        return month + "a";
}       

1 个解决方案

#1


56  

You can obtain months' names in two cases, Nominative:

你可以在两个案例中获得几个月的名字,Nominative:

DateTimeFormatInfo info = CultureInfo.GetCultureInfo("ru-RU").DateTimeFormat;

// February: 2 - 1 (array is zero based) - "Февраль"
Console.Write(info.MonthNames[2 - 1]);

And Genitive:

和资格:

// February: 2 - 1 (array is zero based) - "февраля"
Console.Write(info.MonthGenitiveNames[2 - 1]);

Other cases (e.g. Dative, Accusative) are not supported and we have to implement them manually.

其他情况(例如Dative,Accusative)不受支持,我们必须手动实施。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/02/09/192869efaf96d00a4b4bf0c17ff3e39c.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com