<tfoot id='Sxu3m'></tfoot>

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

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

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

        .NET 是否给了我错误的 2008 年 12 月 29 日的周数

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

                <tbody id='p1XsJ'></tbody>
              <legend id='p1XsJ'><style id='p1XsJ'><dir id='p1XsJ'><q id='p1XsJ'></q></dir></style></legend>

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

                • 本文介绍了.NET 是否给了我错误的 2008 年 12 月 29 日的周数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  根据官方(公历)日历,2008 年 12 月 29 日的周数是 1,因为在 2008 年的最后一天之后第 52 周(即 28/12)一年中只剩下三天或更少的天数.有点奇怪,但是好的,规则就是规则.

                  According to the official (gregorian) calendar, the week number for 29/12/2008 is 1, because after the last day of week 52 (i.e. 28/12) there are three or less days left in the year. Kinda weird, but OK, rules are rules.

                  所以根据这个日历,我们有 2008/2009 年的这些边界值

                  So according to this calendar, we have these boundary values for 2008/2009

                  • 28/12 是第 52 周
                  • 29/12 是第 1 周
                  • 1/1 是第 1 周
                  • 8/1 是第 2 周

                  C# 提供了一个 GregorianCalendar 类,它有一个函数 GetWeekOfYear(date, rule, firstDayOfWeek).

                  C# offers a GregorianCalendar class, that has a function GetWeekOfYear(date, rule, firstDayOfWeek).

                  参数 rule 是一个具有 3 个可能值的枚举:FirstDay、FirstFourWeekDay、FirstFullWeek.根据我的理解,我应该遵循 FirstFourWeekDay 规则,但为了以防万一,我尝试了所有这些规则.

                  The parameter rule is an enumeration with 3 possible values: FirstDay, FirstFourWeekDay, FirstFullWeek. From what I've understood I should go for the FirstFourWeekDay rule, but I tried all of them just in case.

                  最后一个参数告知应将哪一天视为一周的第一天,根据该日历,它是星期一,所以是星期一.

                  The last parameter informs which week day should be considered the first day of the week, according to that calendar it's Monday so Monday it is.

                  所以我启动了一个快速而肮脏的控制台应用程序来测试这个:

                  So I fired up a quick and dirty console app to test this:

                  using System;
                  using System.Globalization;
                  
                  namespace CalendarTest
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                              var cal = new GregorianCalendar();
                              var firstWeekDay = DayOfWeek.Monday;
                              var twentyEighth = new DateTime(2008, 12, 28);
                              var twentyNinth = new DateTime(2008, 12, 29);
                              var firstJan = new DateTime(2009, 1, 1);
                              var eightJan = new DateTime(2009, 1, 8);
                              PrintWeekDays(cal, twentyEighth, firstWeekDay);
                              PrintWeekDays(cal, twentyNinth, firstWeekDay);
                              PrintWeekDays(cal, firstJan, firstWeekDay);
                              PrintWeekDays(cal, eightJan, firstWeekDay);
                              Console.ReadKey();
                          }
                  
                          private static void PrintWeekDays(Calendar cal, DateTime dt, DayOfWeek firstWeekDay)
                          {
                              Console.WriteLine("Testing for " + dt.ToShortDateString());
                              Console.WriteLine("--------------------------------------------");
                              Console.Write(CalendarWeekRule.FirstDay.ToString() + "		");
                              Console.WriteLine(cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, firstWeekDay));
                              Console.Write(CalendarWeekRule.FirstFourDayWeek.ToString() + "	");
                              Console.WriteLine(cal.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, firstWeekDay));
                              Console.Write(CalendarWeekRule.FirstFullWeek.ToString() + "		");
                              Console.WriteLine(cal.GetWeekOfYear(dt, CalendarWeekRule.FirstFullWeek, firstWeekDay));
                              Console.WriteLine("--------------------------------------------");
                          }
                      }
                  }
                  

                  ...这就是我得到的

                  Testing for 28.12.2008
                  --------------------------------------------
                  FirstDay                52
                  FirstFourDayWeek        52
                  FirstFullWeek           51
                  --------------------------------------------
                  Testing for 29.12.2008
                  --------------------------------------------
                  FirstDay                53
                  FirstFourDayWeek        53
                  FirstFullWeek           52
                  --------------------------------------------
                  Testing for 01.01.2009
                  --------------------------------------------
                  FirstDay                1
                  FirstFourDayWeek        1
                  FirstFullWeek           52
                  --------------------------------------------
                  Testing for 08.01.2009
                  --------------------------------------------
                  FirstDay                2
                  FirstFourDayWeek        2
                  FirstFullWeek           1
                  --------------------------------------------
                  

                  如我们所见,以上组合均不符合官方日历(如果您赶时间,请注意 29/12 永远不会成为第 1 周).

                  So as we see, none of the combinations above matches the official calendar (if you are in a hurry, just see that 29/12 never gets week #1).

                  我在这里做错了什么?也许我缺少一些明显的东西?(现在是周五,比利时的工作时间很晚,请多多包涵;))

                  What am I getting wrong here? Maybe there's something glaring that I am missing? (it's Friday and late work hours here in Belgium, bear with me ;))

                  也许我应该解释一下:我需要一个适用于任何年份的函数,返回与我链接的公历相同的结果.所以 2008 年没有特殊的解决方法.

                  Maybe I should explain: what I need is a function that works for any year, returning the same results as the gregorian calendar I linked. So no special workarounds for 2008.

                  推荐答案

                  这个文章 深入研究了问题和可能的解决方法.问题的核心在于 .NET 日历实现似乎并没有忠实地实现 ISO 标准

                  This article looks deeper into the issue and possible workarounds. The hub of the matter is that the .NET calendar implementation does not seem to faithfully implement the ISO standard

                  这篇关于.NET 是否给了我错误的 2008 年 12 月 29 日的周数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:显示全年的 asp.net 可用性日历 下一篇:在 ASP.NET 日历控件的 OnDayRender 事件期间添加 Li

                  相关文章

                  最新文章

                    <bdo id='cwNJl'></bdo><ul id='cwNJl'></ul>
                • <legend id='cwNJl'><style id='cwNJl'><dir id='cwNJl'><q id='cwNJl'></q></dir></style></legend>

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

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

                      <tfoot id='cwNJl'></tfoot>