GetMonthName:有效值介于1和13之间(包括1和13).为什么?

And*_*ndy 11 c# asp.net datetime datetimeformatinfo

我不小心通过了0到DateTimeFormatInfoGetMonthName方法:

DateTimeFormatInfo info = new DateTimeFormatInfo();
var monthName = info.GetMonthName(0);
Run Code Online (Sandbox Code Playgroud)

并得到一个System.ArgumentOutOfRangeException带有此错误消息:有效值介于1和13之间(包括1和13).

传入1到12返回"1月"到"12月",但传入13返回空字符串.

我可以看到为什么月数不是零索引,但是13月是什么?

Jac*_*ope 12

这是因为日历对象可以容纳13个月(根据农历月份来处理日历),请参阅MSDN:

http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx

日历对象可以容纳13个月的日历.对于12个月的日历,空字符串始终作为第13个月的名称返回.


Sir*_*ver 7

根据MSDN

日历对象可以容纳13个月的日历.对于12个月的日历,空字符串始终作为第13个月的名称返回.