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