当前位置: 首页>>代码示例>>C#>>正文


C# Calendar.GetWeekOfYear方法代码示例

本文整理汇总了C#中System.Globalization.Calendar.GetWeekOfYear方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.GetWeekOfYear方法的具体用法?C# Calendar.GetWeekOfYear怎么用?C# Calendar.GetWeekOfYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.Calendar的用法示例。


在下文中一共展示了Calendar.GetWeekOfYear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWeeks

        public Dictionary<string, List<SimpleDateTime>> GetWeeks(string dateTime, System.Globalization.Calendar cal, CultureInfo culture)
        {
            CurrentCalendar = cal;
            UserCulture = culture;
            DateTime safeDate = DateTime.Parse(dateTime);
            Dictionary<string, List<SimpleDateTime>> result = new Dictionary<string, List<SimpleDateTime>>();
            FirstWeekNum = CurrentCalendar.GetWeekOfYear(new DateTime(safeDate.Year, 1, 1), UserCulture.DateTimeFormat.CalendarWeekRule, UserCulture.DateTimeFormat.FirstDayOfWeek);
            CurrentWeekNum = CurrentCalendar.GetWeekOfYear(new DateTime(safeDate.Year, 1, 1), UserCulture.DateTimeFormat.CalendarWeekRule, UserCulture.DateTimeFormat.FirstDayOfWeek);
            LastWeekNum = CurrentCalendar.GetWeekOfYear(new DateTime(safeDate.Year, 12, 31), UserCulture.DateTimeFormat.CalendarWeekRule, UserCulture.DateTimeFormat.FirstDayOfWeek);

            int activeYear = safeDate.Year;
            int currentWeek = 0;
            int currentMonth = 0;
            List<DateTime> weekDays = new List<DateTime>();
            for (int month = 1; month <= 12; month++)
            {
                DateTime activeMonth = new DateTime(activeYear, month, 1, CurrentCalendar);
                int lastDayNum = activeMonth.AddMonths(1).AddDays(-1).Day;
                SimpleDateTime activeDay;
                int weekOfDay = 0;
                for (int day = 1; day <= lastDayNum; day++)
                {
                    activeDay = new SimpleDateTime(UserCulture.Name, new DateTime(activeYear, month, day, CurrentCalendar).ToString());
                    weekOfDay = CurrentCalendar.GetWeekOfYear(activeDay.BaseDate, UserCulture.DateTimeFormat.CalendarWeekRule, UserCulture.DateTimeFormat.FirstDayOfWeek);
                    if (result.Count() == 0 || !result.ContainsKey(weekOfDay.ToString()))
                    {
                        result.Add(weekOfDay.ToString(), new List<SimpleDateTime>());
                        result[weekOfDay.ToString()].Add(activeDay);
                    }
                    else
                    {
                        result[weekOfDay.ToString()].Add(activeDay);
                    }
                    currentWeek = weekOfDay;
                }
                currentMonth = month;
            }
            return result;
        }
开发者ID:Saphora,项目名称:FC,代码行数:39,代码来源:CalendarHelper.cs

示例2: Main

        //Initiate stuff
        public Main()
        {
            InitializeComponent();

            button2.Enabled = false;
            this.comboBox1.Items.AddRange(loadNames());

            myCI = new CultureInfo("en-US");
            myCal = myCI.Calendar;

            // Gets the DTFI properties required by GetWeekOfYear.
            myCWR = myCI.DateTimeFormat.CalendarWeekRule;
            myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

            week = myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW);
            numericUpDown2.Value = week;

            SetTitle();
            loadWeekSales();
        }
开发者ID:dosjos,项目名称:VinLotteri,代码行数:21,代码来源:Main.cs

示例3: ExecutePosTest

 private void ExecutePosTest(string errorNum1, string errorNum2, Calendar myCalendar, int year,
     int month, int day, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     DateTime time;
     int actualDayOfYear, expectedDayOfYear;
     int weekOfYear;
     time = myCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
     expectedDayOfYear = myCalendar.GetDayOfYear(time);
     weekOfYear = myCalendar.GetWeekOfYear(time, rule, firstDayOfWeek);
     actualDayOfYear = this.GetDayOfYear(time, rule, firstDayOfWeek, weekOfYear, myCalendar);
     Assert.Equal(expectedDayOfYear, actualDayOfYear);
 }
开发者ID:kkurni,项目名称:corefx,代码行数:12,代码来源:GregorianCalendarGetWeekOfYears.cs

示例4: Week

        public static int Week( this DateTime date, Calendar calendar, CalendarWeekRule rule, DayOfWeek firstDayOfWeek )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( Contract.Result<int>() > 0 );

            return calendar.GetWeekOfYear( date, rule, firstDayOfWeek );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:7,代码来源:DateTimeExtensions.cs

示例5: WeekNumber

 /// <summary>
 /// Get's this week for a date.
 /// </summary>
 /// <param name="dateTime">The date time.</param>
 /// <param name="calendar">The calendar.</param>
 /// <param name="calendarWeekRule">The calendar week rule.</param>
 /// <param name="firstDayOfWeek">The first day of week.</param>
 /// <returns>The week.</returns>
 public static int WeekNumber(
         this DateTime dateTime,
         Calendar calendar = null,
         CalendarWeekRule calendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
         DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
 {
     if (calendar == null)
         calendar = CultureInfo.CurrentCulture.Calendar;
     int weekNum = calendar.GetWeekOfYear(dateTime, calendarWeekRule, firstDayOfWeek);
     return ((weekNum > 51) && (calendar.GetMonth(dateTime) < 12)) ? 0 : weekNum;
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:19,代码来源:ScheduleExtensions.cs

示例6: GetWeekOfYear

		public static int GetWeekOfYear(this DateTime date, 
			DayOfWeek firstDayOfWeek = DayOfWeek.Sunday, Calendar calendar = null)
		{
			if (calendar == null)
				calendar = _DefaultCalendar;
			
			return calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, firstDayOfWeek);
		}
开发者ID:twocngdagz,项目名称:CalbucciLib.ExtensionsGalore,代码行数:8,代码来源:DateTimeExtensions.cs


注:本文中的System.Globalization.Calendar.GetWeekOfYear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。