GetMonthName:有效值是1和13之间的,具有包容性。为什么? [英] GetMonthName: Valid values are between 1 and 13, inclusive. Why?

查看:180
本文介绍了GetMonthName:有效值是1和13之间的,具有包容性。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心通过0到的DateTimeFormatInfo GetMonthName 方法:

I accidentally passed 0 into DateTimeFormatInfo's GetMonthName method:

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

和得到了 System.ArgumentOutOfRangeException 与此错误信息:有效值为1和13之间,包括

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

通过对12返回传递1一月通过对月但在经过13返回一个空字符串。

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

我明白为什么一个月号码不为零索引,但什么是本月13?

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

推荐答案

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

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

http://msdn.microsoft .COM / EN-US /库/ system.globalization.datetimeformatinfo.getmonthname.aspx

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

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.

这篇关于GetMonthName:有效值是1和13之间的,具有包容性。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆