<legend id='vVqLw'><style id='vVqLw'><dir id='vVqLw'><q id='vVqLw'></q></dir></style></legend>

      <tfoot id='vVqLw'></tfoot>
    1. <i id='vVqLw'><tr id='vVqLw'><dt id='vVqLw'><q id='vVqLw'><span id='vVqLw'><b id='vVqLw'><form id='vVqLw'><ins id='vVqLw'></ins><ul id='vVqLw'></ul><sub id='vVqLw'></sub></form><legend id='vVqLw'></legend><bdo id='vVqLw'><pre id='vVqLw'><center id='vVqLw'></center></pre></bdo></b><th id='vVqLw'></th></span></q></dt></tr></i><div id='vVqLw'><tfoot id='vVqLw'></tfoot><dl id='vVqLw'><fieldset id='vVqLw'></fieldset></dl></div>
          <bdo id='vVqLw'></bdo><ul id='vVqLw'></ul>

        <small id='vVqLw'></small><noframes id='vVqLw'>

      1. 在 asp.net 中收到阿拉伯日期时间错误

        时间:2023-08-26
          • <bdo id='b8GGL'></bdo><ul id='b8GGL'></ul>
            1. <i id='b8GGL'><tr id='b8GGL'><dt id='b8GGL'><q id='b8GGL'><span id='b8GGL'><b id='b8GGL'><form id='b8GGL'><ins id='b8GGL'></ins><ul id='b8GGL'></ul><sub id='b8GGL'></sub></form><legend id='b8GGL'></legend><bdo id='b8GGL'><pre id='b8GGL'><center id='b8GGL'></center></pre></bdo></b><th id='b8GGL'></th></span></q></dt></tr></i><div id='b8GGL'><tfoot id='b8GGL'></tfoot><dl id='b8GGL'><fieldset id='b8GGL'></fieldset></dl></div>

              <small id='b8GGL'></small><noframes id='b8GGL'>

                  <legend id='b8GGL'><style id='b8GGL'><dir id='b8GGL'><q id='b8GGL'></q></dir></style></legend>

                  <tfoot id='b8GGL'></tfoot>
                    <tbody id='b8GGL'></tbody>
                  本文介绍了在 asp.net 中收到阿拉伯日期时间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  I use ADO disconnected mode to get data from database by filling dataset ds. All data come true except the date field

                  string strDate = ds.Tables[0].Rows[0]["H_DT"].ToString();
                  

                  it throws an exception says:

                  Specified time is not supported in this calendar. It should be between 04/30/1900 00:00:00 (Gregorian date) and 11/16/2077 23:59:59 (Gregorian date), inclusive.

                  I tried to write this code

                  System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-sa");
                  System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-sa");
                  

                  to change the culture to Arabic but without any luck.

                  Update

                  The following is screenshot of quick watch for the variable

                  解决方案

                  From DateTime.ToString method

                  The ToString() method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current DateTime instance is earlier than Calendar.MinSupportedDateTime or later than Calendar.MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException.

                  Your ar-sa culture's default calender is UmAlQuraCalendar calender.

                  var culture = CultureInfo.GetCultureInfo("ar-sa");
                  Console.WriteLine(culture.Calendar); // prints UmAlQuraCalendar
                  

                  And from UmAlQuraCalendar.MinSupportedDateTime Property

                  The earliest date and time supported by the UmAlQuraCalendar class, which is equivalent to the first moment of April 30, 1900 C.E. in the Gregorian calendar.

                  Since your DateTime is 1, 1, 1398, it is too normal to throws ArgumentOutOfRangeException.

                  You can solve your problem to provide parameter an IFormatProvider in your DateTime.ToString() method which has GregorianCalendar by default. You can use InvariantCulture for example.

                  string strDate = ds.Tables[0].Rows[0]["H_DT"].ToString(CultureInfo.InvariantCulture);
                  

                  I wrote globalization configuration in web config as ar-sa to be global in all application but I faced the same error, please clarify me, thanks

                  A DateTime belongs on Gregorian calendar by default. From DateTime structure;

                  Each DateTime member implicitly uses the Gregorian calendar to perform its operation, with the exception of constructors that specify a calendar, and methods with a parameter derived from IFormatProvider, such as System.Globalization.DateTimeFormatInfo, that implicitly specifies a calendar.

                  That means your ds.Tables[0].Rows[0]["H_DT"] datetime is Gregorian calender by default. But since you using .ToString() method without any parameter, your method uses your CurrentCulture which is ar-sa since you wrote it in your web.config. And that culture has UmAlQuraCalendar calender by default. Since your datetime out of range in this calender, your code throws exception.

                  Remember, you have a DateTime with 1318 as a year in Gregorian calender, not 1318 as a year in UmAlQuraCalendar calender.

                  As an example;

                  var date = new DateTime(1318, 1, 1);
                  Console.WriteLine(date.ToString(new CultureInfo("ar-sa")));
                  

                  throws ArgumentOutOfRangeException exception because it is exactly the same case of yours. This is a DateTime which is a 1318 year in a Gregorian calender, but there is no representation on UmAlQuraCalendar calender of this datetime because in UmAlQuraCalendar calender, years start with 1900 in Gregorian calender.

                  Take a look at how UmAlQuraCalendar calender implemented;

                  ////////////////////////////////////////////////////////////////////////////
                  //
                  //  Notes about UmAlQuraCalendar
                  //
                  ////////////////////////////////////////////////////////////////////////////
                   /*
                   **  Calendar support range:
                   **      Calendar    Minimum     Maximum
                   **      ==========  ==========  ==========
                   **      Gregorian   1900/04/30   2077/11/17
                   **      UmAlQura    1318/01/01   1500/12/30
                   */
                  

                  这篇关于在 asp.net 中收到阿拉伯日期时间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:按周数获取日期范围c# 下一篇:Google Calendar API,只需知道某人的电子邮件地址就

                  相关文章

                  最新文章

                    <i id='qzmiL'><tr id='qzmiL'><dt id='qzmiL'><q id='qzmiL'><span id='qzmiL'><b id='qzmiL'><form id='qzmiL'><ins id='qzmiL'></ins><ul id='qzmiL'></ul><sub id='qzmiL'></sub></form><legend id='qzmiL'></legend><bdo id='qzmiL'><pre id='qzmiL'><center id='qzmiL'></center></pre></bdo></b><th id='qzmiL'></th></span></q></dt></tr></i><div id='qzmiL'><tfoot id='qzmiL'></tfoot><dl id='qzmiL'><fieldset id='qzmiL'></fieldset></dl></div>

                    <tfoot id='qzmiL'></tfoot>
                  1. <small id='qzmiL'></small><noframes id='qzmiL'>

                    • <bdo id='qzmiL'></bdo><ul id='qzmiL'></ul>

                    1. <legend id='qzmiL'><style id='qzmiL'><dir id='qzmiL'><q id='qzmiL'></q></dir></style></legend>