本文整理汇总了C#中System.Globalization.GregorianCalendar.GetDaysInMonth方法的典型用法代码示例。如果您正苦于以下问题:C# GregorianCalendar.GetDaysInMonth方法的具体用法?C# GregorianCalendar.GetDaysInMonth怎么用?C# GregorianCalendar.GetDaysInMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.GetDaysInMonth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDaysInMonthShouldReturnCorrectCount
public void GetDaysInMonthShouldReturnCorrectCount()
{
var target = new GregorianFiscalCalendar( 7 );
var calendar = new GregorianCalendar();
Assert.Equal( calendar.GetDaysInMonth( 2010, 7 ), target.GetDaysInMonth( 2011, 1 ) );
Assert.Equal( calendar.GetDaysInMonth( 2010, 8 ), target.GetDaysInMonth( 2011, 2 ) );
Assert.Equal( calendar.GetDaysInMonth( 2010, 6 ), target.GetDaysInMonth( 2010, 12 ) );
Assert.Equal( calendar.GetDaysInMonth( 2011, 6 ), target.GetDaysInMonth( 2011, 12 ) );
}
示例2: WorkMonth
public WorkMonth(int year, int month, GermanSpecialDays specialDays, IEnumerable<ShortCut> shortCuts, float hoursPerDay)
{
this.year = year;
this.month = month;
this.hoursPerDay = hoursPerDay;
this.Weeks = new ObservableCollection<WorkWeek>();
this.Days = new ObservableCollection<WorkDay>();
this.ShortCutStatistic = new ObservableCollection<KeyValuePair<string, ShortCutStatistic>>();
// TODO which date should i take?
this.ReloadShortcutStatistic(shortCuts);
var cal = new GregorianCalendar();
WorkWeek lastWeek = null;
for (int day = 1; day <= cal.GetDaysInMonth(year, month); day++) {
var dt = new DateTime(year, month, day);
WorkDay wd = new WorkDay(year, month, day, specialDays);
this.Days.Add(wd);
var weekOfYear = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
if (lastWeek == null || lastWeek.WeekOfYear != weekOfYear) {
lastWeek = new WorkWeek(this, weekOfYear);
lastWeek.PropertyChanged += new PropertyChangedEventHandler(this.WeekPropertyChanged);
this.Weeks.Add(lastWeek);
}
lastWeek.AddDay(wd);
}
}
示例3: GetCalendarDaysFor
public static List<ActivityDay> GetCalendarDaysFor(int? period/*0=yearly, 1=monthly and 2=weekly*/)
{
var days = new List<ActivityDay>();
//var calendar = new ActivityCalendar();
var calendarYear = new GregorianCalendar();
switch (period)
{
case 0:
var dayNumber=(int)DateTime.Now.DayOfWeek;
var weekDay = DateTime.Now.AddDays(-dayNumber);
for (int i=0;i<7;i++)
{
days.Add(new ActivityDay {
Date = weekDay,
Name = calendarYear.GetDayOfWeek(weekDay).ToString(),
Status=true,
ActivityStatus = calendarYear.GetDayOfWeek(weekDay) == DayOfWeek.Friday ?
DayStatus.Holiday
:DayStatus.Active});
weekDay=weekDay.AddDays(1);
}
break;
case 1:
var daysInMonth=calendarYear.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int day = 1; day <= daysInMonth;day++ )
{
var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day);
days.Add(new ActivityDay
{
Date = date,
Name = calendarYear.GetDayOfWeek(date).ToString(),
Status = true,
ActivityStatus = calendarYear.GetDayOfWeek(date) ==
DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active
});
}
break;
default:
var daysInYr=calendarYear.GetDaysInYear(DateTime.Now.Year);
var startOfYr = new DateTime(DateTime.Now.Year, 1, 1);
for (int day = 0; day < daysInYr; day++)
{
var dateOfYr = new ActivityDay {Date=startOfYr.AddDays(day) };
dateOfYr.Name = calendarYear.GetDayOfWeek(dateOfYr.Date).ToString();
dateOfYr.Status = true;
dateOfYr.ActivityStatus = calendarYear.GetDayOfWeek(dateOfYr.Date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active;
days.Add(dateOfYr);
}
break;
}
return days;
}
示例4: PosTest3
public void PosTest3()
{
System.Globalization.Calendar kC = new KoreanCalendar();
System.Globalization.Calendar gC = new GregorianCalendar();
DateTime dateTime = new GregorianCalendar().ToDateTime(2004, 2, 29, 0, 0, 0, 0);
int expectedValue = gC.GetDaysInMonth(dateTime.Year, dateTime.Month, gC.GetEra(dateTime));
int actualValue;
actualValue = kC.GetDaysInMonth(dateTime.Year + 2333, dateTime.Month, kC.GetEra(dateTime));
Assert.Equal(expectedValue, actualValue);
}
示例5: PosTest3
public void PosTest3()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year, month;
int expectedDays, actualDays;
year = GetACommonYear(myCalendar);
month = 2;
expectedDays = s_daysInMonth365[month];
actualDays = myCalendar.GetDaysInMonth(year, month);
Assert.Equal(expectedDays, actualDays);
}
示例6: PosTest4
public void PosTest4()
{
System.Globalization.Calendar kC = new KoreanCalendar();
System.Globalization.Calendar gC = new GregorianCalendar();
DateTime dateTime = new DateTime(_generator.GetInt64(-55) % (DateTime.MaxValue.Ticks + 1));
dateTime = new GregorianCalendar().ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0);
int month = _generator.GetInt16(-55) % 12 + 1;
int expectedValue = gC.GetDaysInMonth(dateTime.Year, month, gC.GetEra(dateTime));
int actualValue;
actualValue = kC.GetDaysInMonth(dateTime.Year + 2333, month, kC.GetEra(dateTime));
Assert.Equal(expectedValue, actualValue);
}
示例7: PosTest4
public void PosTest4()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year, month;
int expectedDays, actualDays;
year = GetACommonYear(myCalendar);
//Get a random value beween 1 and 12 not including 2.
do
{
month = TestLibrary.Generator.GetInt32(-55) % 12 + 1;
} while (2 == month);
expectedDays = s_daysInMonth365[month];
actualDays = myCalendar.GetDaysInMonth(year, month);
Assert.Equal(expectedDays, actualDays);
}
示例8: GetNumberOfWeekdaysInDaysPast
/// <summary>
/// Gets the number of the given weekday in the days past in the month of the given date
/// </summary>
public static int GetNumberOfWeekdaysInDaysPast(DateTime date, DayOfWeek day)
{
var nWeekdays = 0;
var calendar = new GregorianCalendar();
var daysInMonth = calendar.GetDaysInMonth(date.Year, date.Month);
var tempDate = GetStartOfMonth(date);
for (int i = 1; i <= date.Day; i++, tempDate = tempDate.AddDays(1))
{
if (tempDate.DayOfWeek == DayOfWeek.Sunday)
{
nWeekdays++;
}
}
return nWeekdays;
}
示例9: PosTest9
public void PosTest9()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year, month;
int expectedDays, actualDays;
year = myCalendar.MaxSupportedDateTime.Year;
month = 12;
expectedDays = (IsLeapYear(year)) ? s_daysInMonth366[month] : s_daysInMonth365[month];
actualDays = myCalendar.GetDaysInMonth(year, month);
Assert.Equal(expectedDays, actualDays);
}
示例10: GetDay
/// <summary>
/// 获得某年某月的天数(命名空间System.Globalization)
/// </summary>
/// <returns></returns>
public static int GetDay()
{
GregorianCalendar gc = new GregorianCalendar();
return gc.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
}
示例11: NegTest4
public void NegTest4()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year, month;
year = myCalendar.MinSupportedDateTime.Year - 100;
month = -1 * _generator.GetInt32(-55);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.GetDaysInMonth(year, month);
});
}
示例12: NegTest3
public void NegTest3()
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
int year, month;
year = GetAYear(myCalendar);
month = 13 + _generator.GetInt32(-55) % (int.MaxValue - 12);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.GetDaysInMonth(year, month);
});
}
示例13: AddRecurringItem
// This adds a recurring item to the list as many times as needed (and with proper dates)
private void AddRecurringItem(ICollection<AgendaItem> list, AgendaItem item, DateTime from, DateTime to)
{
GregorianCalendar calendar = new GregorianCalendar();
TimeSpan alarmoffset = item.startdate - item.alarmdate;
DateTime d = from;
// Advance d to the first occurence of the item within this time period
switch(item.recur)
{
case AgendaItemRecur.Weekly:
if((int)d.DayOfWeek < (int)item.startdate.DayOfWeek)
d = d.AddDays((int)item.startdate.DayOfWeek - (int)d.DayOfWeek);
else if((int)d.DayOfWeek > (int)item.startdate.DayOfWeek)
d = d.AddDays((7 - (int)d.DayOfWeek) + (int)item.startdate.DayOfWeek);
break;
case AgendaItemRecur.Monthly:
if(d.Day < item.startdate.Day)
d = d.AddDays(item.startdate.Day - d.Day);
else if(d.Day > item.startdate.Day)
d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);
break;
case AgendaItemRecur.Annually:
// First advance to the correct day in the month
// so that we don't skip over the day when advancing by months
if(d.Day < item.startdate.Day)
d = d.AddDays(item.startdate.Day - d.Day);
else if(d.Day > item.startdate.Day)
d = d.AddDays((calendar.GetDaysInMonth(d.Year, d.Month) - d.Day) + item.startdate.Day);
// Now advance by months
if(d.Month < item.startdate.Month)
d = d.AddMonths(item.startdate.Month - d.Month);
else if(d.Month > item.startdate.Month)
d = d.AddMonths((12 - d.Month) + item.startdate.Month);
break;
}
// We check how many times we can repeat the item within the
// given timespan and add the item repeatedly
while(d.Ticks <= to.Ticks)
{
// Add item with proper dates
AgendaItem newitem = item;
newitem.startdate = d.AddHours(item.startdate.Hour).AddMinutes(item.startdate.Minute);
newitem.alarmdate = newitem.startdate.Subtract(alarmoffset);
TimeSpan span = newitem.startdate - newitem.originstartdate;
switch(item.recur)
{
case AgendaItemRecur.Weekly: newitem.recursions = (int)Math.Round(span.TotalDays / 7.0d); break;
case AgendaItemRecur.Monthly: newitem.recursions = (int)Math.Round(span.TotalDays / 30.4375d); break;
case AgendaItemRecur.Annually: newitem.recursions = (int)Math.Round(span.TotalDays / 365.25d); break;
}
list.Add(newitem);
// Advance date to the next date when the item recurs
switch(item.recur)
{
case AgendaItemRecur.Weekly:
d = d.AddDays(7);
break;
case AgendaItemRecur.Monthly:
//d = d.AddDays(calendar.GetDaysInMonth(d.Year, d.Month));
d = d.AddMonths(1);
break;
case AgendaItemRecur.Annually:
d = d.AddYears(1);
break;
}
}
}
示例14: getMonthDays
/// <summary>
/// 取得某个年月的天数
/// </summary>
/// <returns></returns>
public static int getMonthDays(int year, int month)
{
GregorianCalendar gc = new GregorianCalendar();
return gc.GetDaysInMonth(year, month);
}
示例15: GetNumberOfDaysInMonth
public static int GetNumberOfDaysInMonth(DateTime date)
{
var calendar = new GregorianCalendar();
return calendar.GetDaysInMonth(date.Year, date.Month);
}