GetMonthName: Valid values are between 1 and 13, inclusive. Why?

青春壹個敷衍的年華 提交于 2019-12-19 05:22:21

问题


I accidentally passed 0 into DateTimeFormatInfo's GetMonthName method:

DateTimeFormatInfo info = new DateTimeFormatInfo();
var monthName = info.GetMonthName(0);

and got a System.ArgumentOutOfRangeException with this error message: Valid values are between 1 and 13, inclusive.

Passing in 1 through to 12 return "January" through to "December" but passing in 13 returns an empty string.

I can see why month numbers are not zero indexed, but what's month 13 for?


回答1:


It's because calendar objects can accomodate 13 months (to handle calendars based on lunar months), see MSDN:

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

Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.




回答2:


According to MSDN

Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.




回答3:


I guess it is used to determine the leap day in the julian calendar ( http://en.wikipedia.org/wiki/Julian_calendar ). As most of use use Gregorian calender just do not worry.



来源:https://stackoverflow.com/questions/5991766/getmonthname-valid-values-are-between-1-and-13-inclusive-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!