程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了1400 年波斯历的问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决1400 年波斯历的问题?

开发过程中遇到1400 年波斯历的问题的问题如何解决?下面主要结合日常开发的经验,给出你关于1400 年波斯历的问题的解决方法建议,希望对你解决1400 年波斯历的问题有所启发或帮助;

我想在 C# 中使用波斯日历类将 波斯日期 更改为标准 datetiR_348_11845@e 格式。 但是由于将年份更改为 1400,它抛出异常,如下所示:

ArgumentOutOfRangeException: SpecifIEd time is not supported in this calendar. It should be @R_801_7000@n 22/03/22 12:00:00 AM (Gregorian datE) and 99/12/31 11:59:59 PM (Gregorian datE),inclusive. (Parameter 'time')
Actual value was 0.

我检查了波斯历课,发现了这个:

if (year < 1 || year > MaxCalendarYear || month < 1 || month > 12)
{
  throw new ArgumentOutOfRangeException(null,SR.ArgumentOutOfRange_BadYearMonthDay);
}

那个抛出异常。 现在我应该怎么做才能解决这个问题?

解决方法

为什么不在 PersianCalendar 类的帮助下显式转换?

using System.Globalization;

...

// what does Gregorian date correspond to Persian new year (1400)? 
int year = 1400;
int month = 1;
int day = 1;

datetiR_348_11845@e result = new PersianCalendar().TodatetiR_348_11845@e(year,month,day,0);

Console.WriteLine($"{result:dd MMMM yyyy}");

结果:

21 March 2021

ArgumentOutOfRangeException 当至少一个参数超出范围时被抛出:@H_966_5@month 应该在 1..12 之内等等。

,

您将一个空的 datetiR_348_11845@e(例如 new datetiR_348_11845@e())传递给强大的 PersianCalendar 的方法之一。

请注意,datetiR_348_11845@e 是一个 struct(不是 class),任何类型为 datetiR_348_11845@e 且未初始化/设置的属性或变量都将具有此最小值价值。

也许您正在反序列化一个没有此值但类的属性不可为空的 json。也许数据库中的列为空但模型的属性不可为空等。

详情

该异常是由 PersianCalendar 的 @R_696_10943@kTicksRange 方法抛出的,该方法被类中的许多方法调用:

internal static void @R_696_10943@kTicksRange(long ticks)
{
    if (ticks < s_minDate.Ticks || ticks > s_maxDate.Ticks)
    {
        throw new ArgumentOutOfRangeException(
            "time",ticks,SR.Format(SR.ArgumentOutOfRange_CalendarRange,s_minDate,s_maxDatE));
    }
}

您收到的错误消息以字符串结尾:Actual value was 0.。这意味着传入的 datetiR_348_11845@e 有 0 个刻度,这意味着它是空的。

例如:

try
{
    new PersianCalendar().GetYear(time: new datetiR_348_11845@e());
}
catch (Exception eX)
{
    Console.WriteLine(ex.messagE);
}

结果:

Specified time is not supported in this calendar. It should be @R_801_7000@n 22/03/0622 00:00:00 (Gregorian datE) and 31/12/999@R_607_11201@3:59:59 (Gregorian datE),inclusive. (Parameter 'time')
Actual value was 0.  

请注意'实际值为 0.`。

另请注意,在我的语言环境中,例外情况更清楚一些,因为日期包含 4 位数字年份。

如果我们使用无效日期,但不是空的,则异常消息的结尾会有所不同:

new PersianCalendar().GetYear(time: new datetiR_348_11845@e(year: 622,month: 1,day: 1));

结果:

Specified time is not ... 
... 'time')
Actual value was 195968160000000000.

大佬总结

以上是大佬教程为你收集整理的1400 年波斯历的问题全部内容,希望文章能够帮你解决1400 年波斯历的问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。