當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTime.Quarter方法代碼示例

本文整理匯總了C#中System.DateTime.Quarter方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.Quarter方法的具體用法?C# DateTime.Quarter怎麽用?C# DateTime.Quarter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.Quarter方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShouldReturnCorrectQuarter

        public void ShouldReturnCorrectQuarter(int year, int month, int day, int expectedQuarter)
        {
            DateTime dt = new DateTime(year, month, day);

            int quarter = dt.Quarter();

            quarter.ShouldBe(expectedQuarter);
        }
開發者ID:CedricDumont,項目名稱:CExtensions-Net,代碼行數:8,代碼來源:DateTimeExtensionsTest.cs

示例2: TestQuarterCalc

        public void TestQuarterCalc()
        {
            for(int month = 1; month <= 12; month++)
            {
                DateTime qtrTest = new DateTime(2013, month, 5);

                int quarter = qtrTest.Quarter();

                if(qtrTest.Month >= 1 && qtrTest.Month <= 3)
                    Assert.AreEqual(1, quarter);
                else if(qtrTest.Month >= 4 && qtrTest.Month <= 6)
                    Assert.AreEqual(2, quarter);
                else if(qtrTest.Month >= 7 && qtrTest.Month <= 9)
                    Assert.AreEqual(3, quarter);
                else if(qtrTest.Month >= 10 && qtrTest.Month <= 12)
                    Assert.AreEqual(4, quarter);
            }
        }
開發者ID:vgribok,項目名稱:Aspectacular,代碼行數:18,代碼來源:DateTImeExtTest.cs

示例3: QuarterWithCalendarShouldReturnExpectedResult

 public void QuarterWithCalendarShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 3, 1 );
     var calendar = new GregorianFiscalCalendar( 7 );
     var actual = date.Quarter( calendar );
     Assert.Equal( 3, actual ); // because fiscal calendar starts in July
 }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:7,代碼來源:DateTimeExtensionsTest.cs

示例4: IsDateInYearAndQuarter

 public static Boolean IsDateInYearAndQuarter(DateTime dateTime, Int32 year, Int32 quarter)
 {
     CheckQuarter(quarter);
       return ((dateTime.Year == year) && (dateTime.Quarter() == quarter));
 }
開發者ID:ctimmons,項目名稱:cs_utilities,代碼行數:5,代碼來源:DateTimeUtils.cs

示例5: QuarterShouldReturnExpectedResult

 public void QuarterShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 4, 1 );
     var actual = date.Quarter();
     Assert.Equal( 2, actual );
 }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:6,代碼來源:DateTimeExtensionsTest.cs

示例6: Includes

        /// <summary>
        /// Returns true if date falls on specified quarter or range of quarters
        /// </summary>
        /// <param name="aDate"></param>
        /// <returns></returns>
        public override bool Includes(DateTime aDate)
        {
            //check for valid args
            if (this.Start == Quarter.Unset || (this.End.HasValue && this.End.Value == Quarter.Unset))
                throw new ArgumentException();

            bool result;

            if (this.End.HasValue)
            {
                //range
                if (this.End.Value >= this.Start)
                    result = (aDate.Quarter(this.StartOfYear) <= this.End.Value && aDate.Quarter(this.StartOfYear) >= this.Start);
                else
                    result = (aDate.Quarter(this.StartOfYear) <= this.End.Value || aDate.Quarter(this.StartOfYear)>= this.Start);
            }
            else
                result = (this.Start == aDate.Quarter(this.StartOfYear));

            return result;
        }
開發者ID:barake,項目名稱:TemporalToolkit,代碼行數:26,代碼來源:TEQuarter.cs

示例7: FormatQuarterPart

        protected virtual string FormatQuarterPart( DateTime value, string format, IFormatProvider formatProvider )
        {
            Arg.NotNullOrEmpty( format, nameof( format ) );
            Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );

            switch ( format.Length )
            {
                case 1: // q
                    return value.Quarter( Calendar ).ToString( formatProvider );
                case 2: // qq
                    return value.Quarter( Calendar ).ToString( "00", formatProvider );
                case 3: // qqq
                    return string.Format( formatProvider, SR.ShortQuarterFormat, value.Quarter( Calendar ) );
            }

            // qqqq*
            return string.Format( formatProvider, SR.QuarterFormat, value.Quarter( Calendar ) );
        }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:18,代碼來源:DateTimeFormatProvider.cs

示例8: Quarter

        public static int Quarter( this Calendar calendar, DateTime date )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( Contract.Result<int>() > 0 );
            Contract.Ensures( Contract.Result<int>() < 5 );

            return date.Quarter( calendar );
        }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:8,代碼來源:CalendarExtensions.cs

示例9: EndOfQuarter

        public static DateTime EndOfQuarter( this Calendar calendar, DateTime date )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( Contract.Result<DateTime>().Quarter( calendar ) == Contract.OldValue( date.Quarter( calendar ) ) );

            return date.EndOfQuarter( calendar );
        }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:8,代碼來源:CalendarExtensions.cs


注:本文中的System.DateTime.Quarter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。