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


C# Globalization.Calendar类代码示例

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


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

示例1: Clear

 // Methods
 public void Clear(Calendar calendar)
 {
   if (this[calendar] != null)
   {
     this.Remove(calendar);
   }
 }
开发者ID:heimanhon,项目名称:researchwork,代码行数:8,代码来源:SupportClass.cs

示例2: AssertEquivalent

        /// <summary>
        /// Checks that each day from the given start year to the end year (inclusive) is equal
        /// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
        /// and the number of months (and leap year status) in each year is checked.
        /// </summary>
        internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
        {
            // We avoid asking the BCL to create a DateTime on each iteration, simply
            // because the BCL implementation is so slow. Instead, we just check at the start of each month that
            // we're at the date we expect.
            DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);
            for (int year = fromYear; year <= toYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
                Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
                for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
                {
                    // Sanity check at the start of each month. Even this is surprisingly slow.
                    // (These three tests make up about 20% of the total execution time for the test.)
                    Assert.AreEqual(year, bcl.GetYear(bclDate));
                    Assert.AreEqual(month, bcl.GetMonth(bclDate));
                    Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));

                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                        "Year: {0}; Month: {1}", year, month);
                    Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
                    for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
                    {
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
                            "Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
                        Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                        bclDate = bclDate.AddDays(1);
                    }
                }
            }
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:40,代码来源:BclEquivalenceHelper.cs

示例3: DateTimeFormatInfo

 public DateTimeFormatInfo()
 {
     // Construct an invariant culture DateTimeFormatInfo
     char[] comma = new char[] { ',' };
     this.isReadOnly = true;
     this.abbreviatedDayNames = "Sun,Mon,Tue,Wed,Thu,Fri,Sat".Split(comma);
     this.abbreviatedMonthGenitiveNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,".Split(comma);
     this.abbreviatedMonthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,".Split(comma);
     this.amDesignator = "AM";
     this.calendarWeekRule = CalendarWeekRule.FirstDay;
     this.dateSeparator = "/";
     this.dayNames = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".Split(comma);
     this.firstDayOfWeek = DayOfWeek.Sunday;
     this.fullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss";
     this.longDatePattern = "dddd, dd MMMM yyyy";
     this.longTimePattern = "HH:mm:ss";
     this.monthDayPattern = "MMMM dd";
     this.monthGenitiveNames = "January,February,March,April,May,June,July,August,September,October,November,December,".Split(comma);
     this.monthNames = "January,February,March,April,May,June,July,August,September,October,November,December,".Split(comma);
     this.nativeCalendarName = "Gregorian Calendar";
     this.pmDesignator = "PM";
     this.rfc1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
     this.shortDatePattern = "MM/dd/yyyy";
     this.shortestDayNames = "Su,Mo,Tu,We,Th,Fr,Sa".Split(comma);
     this.shortTimePattern = "HH:mm";
     this.sortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
     this.timeSeparator = ":";
     this.universalSortableDateTimePattern = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'";
     this.yearMonthPattern = "yyyy MMMM";
     this.calendar = new GregorianCalendar();
 }
开发者ID:memsom,项目名称:dotNetAnywhere-wb,代码行数:31,代码来源:DateTimeFormatInfo.cs

示例4: GetWeekOfYear

      /// <summary>
      /// Gets the week of the year for the specified date, culture and calendar.
      /// </summary>
      /// <param name="info">The <see cref="CultureInfo"/> to use.</param>
      /// <param name="cal">The <see cref="Calendar"/> to use.</param>
      /// <param name="date">The date value to get the week of year for.</param>
      /// <returns>The week of the year.</returns>
      public static int GetWeekOfYear(CultureInfo info, Calendar cal, DateTime date)
      {
         CultureInfo ci = info ?? CultureInfo.CurrentUICulture;
         Calendar c = cal ?? ci.Calendar;

         return c.GetWeekOfYear(date, ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);
      }
开发者ID:sulerzh,项目名称:DbExporter,代码行数:14,代码来源:DateMethods.cs

示例5: Age

        /// <summary>
        /// Initializes a new instance of <see cref="Age"/>.
        /// </summary>
        /// <param name="start">The date and time when the age started.</param>
        /// <param name="end">The date and time when the age ended.</param>
        /// <param name="calendar">Calendar used to calculate age.</param>
        public Age(DateTime start, DateTime end, Calendar calendar)
        {
            if (start > end) throw new ArgumentException("The starting date cannot be later than the end date.");

            var startDate = start.Date;
            var endDate = end.Date;

            _years = _months = _days = 0;
            _days += calendar.GetDayOfMonth(endDate) - calendar.GetDayOfMonth(startDate);
            if (_days < 0)
            {
                _days += calendar.GetDaysInMonth(calendar.GetYear(startDate), calendar.GetMonth(startDate));
                _months--;
            }
            _months += calendar.GetMonth(endDate) - calendar.GetMonth(startDate);
            if (_months < 0)
            {
                _months += calendar.GetMonthsInYear(calendar.GetYear(startDate));
                _years--;
            }
            _years += calendar.GetYear(endDate) - calendar.GetYear(startDate);

            var ts = endDate.Subtract(startDate);
            _totalDays = (Int32)ts.TotalDays;
        }
开发者ID:weedazarhub,项目名称:gryffe,代码行数:31,代码来源:Age.cs

示例6: PersianCulture

   public PersianCulture(string cultureName, bool useUserOverride)
      : base(cultureName, useUserOverride)
   {
      cal = base.OptionalCalendars[0];
      var optionalCalendars = new List<System.Globalization.Calendar>();
      optionalCalendars.AddRange(base.OptionalCalendars);
      optionalCalendars.Insert(0, new PersianCalendar());
      Type formatType = typeof(DateTimeFormatInfo);
      Type calendarType = typeof(System.Globalization.Calendar);
      PropertyInfo idProperty = calendarType.GetProperty("ID", BindingFlags.Instance | BindingFlags.NonPublic);
      FieldInfo optionalCalendarfield = formatType.GetField("optionalCalendars", BindingFlags.Instance | BindingFlags.NonPublic);
      var newOptionalCalendarIDs = new Int32[optionalCalendars.Count];

      for (int i = 0; i < newOptionalCalendarIDs.Length; i++)

         newOptionalCalendarIDs[i] = (Int32)idProperty.GetValue(optionalCalendars[i], null);
      optionalCalendarfield.SetValue(DateTimeFormat, newOptionalCalendarIDs);

      optionals = optionalCalendars.ToArray();

      cal = optionals[0];

      DateTimeFormat.Calendar = optionals[0];

      DateTimeFormat.MonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
      DateTimeFormat.MonthGenitiveNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
      DateTimeFormat.AbbreviatedMonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
      DateTimeFormat.AbbreviatedMonthGenitiveNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
      DateTimeFormat.AbbreviatedDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
      DateTimeFormat.ShortestDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
      DateTimeFormat.DayNames = new string[] { "یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
      DateTimeFormat.AMDesignator = "ق.ظ";
      DateTimeFormat.PMDesignator = "ب.ظ";

   }
开发者ID:CharlesZHENG,项目名称:BlogEngine.NET,代码行数:35,代码来源:PersianCulture.cs

示例7: VerifyXamlValues

 private void VerifyXamlValues(Calendar calendar)
 {
     Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, new DateTime(2008, 4, 30)));
     Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, new DateTime(2008, 4, 30)));
     Assert.IsTrue(CompareDates(calendar.DisplayDate, new DateTime(2008, 4, 30)));
     Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, new DateTime(2010, 4, 30)));
     _isLoaded = false;
 }
开发者ID:dfr0,项目名称:moon,代码行数:8,代码来源:CalendarTest.cs

示例8: DateTimeFormatter

 public DateTimeFormatter(string dateTimePattern, Calendar calendar)
     : this(dateTimePattern,
         calendar,
         Thread.CurrentThread.CurrentCulture.DateTimeFormat.AMDesignator,
         Thread.CurrentThread.CurrentCulture.DateTimeFormat.PMDesignator)
 {
     // Nothing.
 }
开发者ID:AndrewM-,项目名称:Peygir,代码行数:8,代码来源:DateTimeFormatter.cs

示例9: ExecutePosTest

 private void ExecutePosTest(Calendar myCalendar, int year, int month, int day, int hour, int minute,
     int second, int millisecond, int era)
 {
     DateTime actualTime, expectedTime;
     expectedTime = new DateTime(year, month, day, hour, minute, second, millisecond);
     actualTime = myCalendar.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     Assert.Equal(expectedTime, actualTime);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:GregorianCalendarToDateTime.cs

示例10: ReadOnlyTest

 public static void ReadOnlyTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
 {
     Assert.False(calendar.IsReadOnly);
     var readOnlyCal = Calendar.ReadOnly(calendar);
     Assert.True(readOnlyCal.IsReadOnly, "expect readOnlyCal.IsReadOnly returns true");
     var colnedCal = (Calendar) readOnlyCal.Clone();
     Assert.False(colnedCal.IsReadOnly, "expect colnedCal.IsReadOnly returns false");
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:8,代码来源:Calendars.netstandard1.7.cs

示例11: GetDefaultInstance

        /*=================================GetDefaultInstance==========================
        **Action: Internal method to provide a default intance of TaiwanCalendar.  Used by NLS+ implementation
        **       and other calendars.
        **Returns:
        **Arguments:
        **Exceptions:
        ============================================================================*/

        internal static Calendar GetDefaultInstance()
        {
            if (s_defaultInstance == null)
            {
                s_defaultInstance = new TaiwanCalendar();
            }
            return (s_defaultInstance);
        }
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:16,代码来源:TaiwanCalendar.cs

示例12: GregorianCalendarHelper

 internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo)
 {
     this.m_Cal = cal;
     this.m_EraInfo = eraInfo;
     this.m_minDate = this.m_Cal.MinSupportedDateTime;
     this.m_maxYear = this.m_EraInfo[0].maxEraYear;
     this.m_minYear = this.m_EraInfo[0].minEraYear;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:8,代码来源:GregorianCalendarHelper.cs

示例13: MonthCalendarControl

        public MonthCalendarControl()
        {
            InitializeComponent();

            _DisplayMonth = _DisplayStartDate.Month;
            _DisplayYear = _DisplayStartDate.Year;
            _cultureInfo = new CultureInfo(CultureInfo.CurrentUICulture.LCID);
            sysCal = _cultureInfo.Calendar;
        }
开发者ID:Exomnius,项目名称:TogetherIsBetter,代码行数:9,代码来源:MonthCalendarControl.xaml.cs

示例14: MonthCalendarControl

        public MonthCalendarControl()
        {
            InitializeComponent();

            _displayMonth = _DisplayStartDate.Month;
            _displayYear = _DisplayStartDate.Year;
            sysCal = Thread.CurrentThread.CurrentUICulture.Calendar;

            BuildCalendarUi();
        }
开发者ID:kneefer,项目名称:UniversityReservationSystem,代码行数:10,代码来源:MonthCalendarControl.xaml.cs

示例15: Halfyear

 // ----------------------------------------------------------------------
 public static TimeSpan Halfyear( Calendar calendar, int year, YearHalfyear yearHalfyear )
 {
     YearMonth[] halfyearMonths = TimeTool.GetMonthsOfHalfyear( yearHalfyear );
     TimeSpan duration = TimeSpec.NoDuration;
     foreach ( YearMonth halfyearMonth in halfyearMonths )
     {
         duration = duration.Add( Month( calendar, year, halfyearMonth ) );
     }
     return duration;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:11,代码来源:Duration.cs


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