本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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 );
}
示例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;
}
示例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);
}