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


C# Date.AddDays方法代碼示例

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


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

示例1: GetPrintNumber

 // GetLeMondePrintNumber
 public static int GetPrintNumber(Date date)
 {
     // Le monde - 2012-12-02 - no 21110.pdf
     // Le monde - 2012-10-12 - no 21066.pdf
     // Le monde - 2012-07-19 - no 20993.pdf
     // pas de journal le 1er mai sauf si c'est un dimanche, journal le dimanche 1er mai 2011
     // Test_GetLeMondePrintNumber("2012-04-29"); // ok  20925
     // Test_GetLeMondePrintNumber("2012-05-02"); // ok  20926
     Date dateRef = new Date(2012, 12, 2);
     int noRef = 21110;
     while (date > dateRef)
     {
         if (dateRef.DayOfWeek != DayOfWeek.Sunday && (dateRef.Month != 5 || dateRef.Day != 1 || dateRef.DayOfWeek == DayOfWeek.Sunday))
             noRef++;
         dateRef = dateRef.AddDays(1);
     }
     while (date < dateRef)
     {
         if (dateRef.DayOfWeek != DayOfWeek.Monday && (dateRef.Month != 5 || dateRef.Day != 1 || dateRef.DayOfWeek == DayOfWeek.Sunday))
             noRef--;
         dateRef = dateRef.AddDays(-1);
     }
     if (date != dateRef) throw new PBException("error date not found {0}", date.ToString());
     return noRef;
 }
開發者ID:labeuze,項目名稱:source,代碼行數:26,代碼來源:le_monde_f2.cs

示例2: CanAddDays

        public void CanAddDays()
        {
            Date d1 = new Date(2012, 2, 29);
            Date d2 = d1.AddDays(1);

            Assert.AreEqual(2012, d2.Year);
            Assert.AreEqual(3, d2.Month);
            Assert.AreEqual(1, d2.Day);
        }
開發者ID:joaofx,項目名稱:csharp-date,代碼行數:9,代碼來源:DateTests.cs

示例3: Test_02

 public static void Test_02()
 {
     Date date = new Date(2012, 12, 10);
     for (int i = 0; i < 100; i++)
     {
         //wr.Print("{0,-8} {1} {2,6}", GetWeekDayName(date.DayOfWeek), date, GetLeMondePrintNumber(date));
         wr.Print("{0,-10:dddd} {1:yyyy-MM-dd} {2,6}", date, date, le_monde.GetPrintNumber(date));
         date = date.AddDays(-1);
     }
 }
開發者ID:labeuze,項目名稱:source,代碼行數:10,代碼來源:le_monde_f.cs

示例4: GetDayInsideDateGap

        //public static bool IsDayInsideDateGap(int day, Date date, int gapDayBefore = 0, int gapDayAfter = 0)
        public static Date? GetDayInsideDateGap(int day, Date expectedDate, int gapDayBefore = 0, int gapDayAfter = 0)
        {
            int expectedDay = expectedDate.Day;
            if (day == expectedDay)
                //return true;
                return expectedDate;

            if (gapDayBefore > 0)
            {
                Date minDate = expectedDate.AddDays(-gapDayBefore);
                int minDay = minDate.Day;
                if (minDay < expectedDay)
                {
                    if (day >= minDay && day < expectedDay)
                        //return true;
                        return new Date(expectedDate.Year, expectedDate.Month, day);
                }
                else // previous month
                {
                    if (day >= 1 && day < expectedDay)
                        //return true;
                        return new Date(expectedDate.Year, expectedDate.Month, day);
                    if (day >= minDay && day <= Date.DaysInMonth(minDate.Year, minDate.Month))
                        //return true;
                        return new Date(minDate.Year, minDate.Month, day);
                }
            }

            if (gapDayAfter > 0)
            {
                Date maxDate = expectedDate.AddDays(gapDayAfter);
                int maxDay = maxDate.Day;
                if (maxDay > expectedDay)
                {
                    if (day > expectedDay && day <= maxDay)
                        //return true;
                        return new Date(expectedDate.Year, expectedDate.Month, day);
                }
                else // next month
                {
                    if (day > expectedDay && day <= Date.DaysInMonth(expectedDate.Year, expectedDate.Month))
                        //return true;
                        return new Date(expectedDate.Year, expectedDate.Month, day);
                    if (day >= 1 && day <= maxDay)
                        //return true;
                        return new Date(maxDate.Year, maxDate.Month, day);
                }
            }

            //return false;
            return null;
        }
開發者ID:labeuze,項目名稱:source,代碼行數:53,代碼來源:Date2.cs

示例5: GetNearestWeekday

 public static Date GetNearestWeekday(Date date, DayOfWeek weekday)
 {
     int i = (int)weekday - (int)date.DayOfWeek;
     if (i == 0)
         return date;
     if (i > 3)
         return date.AddDays(i - 7);
     if (i < -3)
         return date.AddDays(i + 7);
     return date.AddDays(i);
 }
開發者ID:labeuze,項目名稱:source,代碼行數:11,代碼來源:Date2.cs

示例6: TestDateAddDaysInvalidResults

 public void TestDateAddDaysInvalidResults()
 {
     Date date = new Date(1, 1, 1);
     Action test = () => date.AddDays(-2);
     test.ShouldThrow<ArgumentOutOfRangeException>().WithMessage(Strings.Date_InvalidAddedOrSubtractedResults + "\r\nParameter name: value");
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:6,代碼來源:DateAndTimeOfDayTests.cs

示例7: TestDateAddDays

 public void TestDateAddDays()
 {
     Date date = new Date(2013, 8, 12);
     Date result = date.AddDays(1);
     result.Should().Be(new Date(2013, 8, 13));
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:6,代碼來源:DateAndTimeOfDayTests.cs

示例8: GetEveryTwoWeekPrintDate

 public static Date GetEveryTwoWeekPrintDate(int printNumber, int refNumber, Date refDate)
 {
     return refDate.AddDays((printNumber - refNumber) * 14);
 }
開發者ID:labeuze,項目名稱:source,代碼行數:4,代碼來源:zprint.cs

示例9: GetWeeklyPrintDate

 public static Date GetWeeklyPrintDate(int printNumber, int refNumber, Date refDate)
 {
     return refDate.AddDays((printNumber - refNumber) * 7);
 }
開發者ID:labeuze,項目名稱:source,代碼行數:4,代碼來源:zprint.cs

示例10: GetSampleValue

 private static object GetSampleValue(Type fieldType, bool allowNull, int n)
 {
     if (fieldType == typeof(string))
     {
         return "Sample Data " + n;
     }
     if (allowNull)
     {
         return GetSampleValue(fieldType.GetGenericArguments()[0], false, n);
     }
     if (fieldType == typeof(int))
     {
         return (int)(1 + n);
     }
     if (fieldType == typeof(short))
     {
         return (short)(1 + n);
     }
     if (fieldType == typeof(long))
     {
         return (long)(1 + n);
     }
     if (fieldType == typeof(float))
     {
         return (float)(0.1 + n);
     }
     if (fieldType == typeof(double))
     {
         return (double)(0.1 + n);
     }
     if (fieldType == typeof(bool))
     {
         return (n % 2) == 0;
     }
     if (fieldType == typeof(DateTime))
     {
         var dt = new DateTime(2008, 3, 6, 12, 24, 35);
         return dt.AddDays(n);
     }
     if (fieldType == typeof(Date))
     {
         var d = new Date(2008, 3, 17);
         return d.AddDays(n);
     }
     if (fieldType == typeof(Time))
     {
         var t = new Time(12, 24, 35);
         return t.AddMinutes(n);
     }
     if (fieldType == typeof(Guid))
     {
         return Util.NewGuid();
     }
     if (fieldType == typeof(byte))
     {
         return (byte)n;
     }
     if (fieldType == typeof(sbyte))
     {
         return (sbyte)n;
     }
     if (fieldType == typeof(decimal))
     {
         return (decimal)n;
     }
     if (fieldType == typeof(byte[]))
     {
         return new byte[] { 61, 62, 63 };
     }
     if (fieldType.IsEnum)
     {
         string[] ss = Enum.GetNames(fieldType);
         string name = ss[n % ss.Length];
         return Enum.Parse(fieldType, name);
     }
     return null;
 }
開發者ID:991899783,項目名稱:DbEntry,代碼行數:77,代碼來源:DbEntryDesignerDataSourceView.cs

示例11: CanCompareDates

		public void CanCompareDates()
		{
			Date d1 = new Date(2013, 4, 5);
			Date d2 = new Date(2013, 4, 5);
			Date d3 = new Date(2014, 4, 8);

			Assert.IsTrue(d1 == d2);
			Assert.IsTrue(d1 != d3);
			Assert.IsTrue(d1 <= d2);
			Assert.IsTrue(d1 >= d2);
			Assert.IsTrue(d1 < d1.AddDays(3));
			Assert.IsTrue(d1 < d1.AddMonths(4));
			Assert.IsTrue(d1 < d1.AddYears(5));
			Assert.IsTrue(d1 <= d1.AddDays(3));
			Assert.IsTrue(d1 <= d1.AddMonths(4));
			Assert.IsTrue(d1 <= d1.AddYears(5));
			Assert.IsTrue(d1 > d1.AddDays(-3));
			Assert.IsTrue(d1 > d1.AddMonths(-4));
			Assert.IsTrue(d1 > d1.AddYears(-5));
			Assert.IsTrue(d1 >= d1.AddDays(-3));
			Assert.IsTrue(d1 >= d1.AddMonths(-4));
			Assert.IsTrue(d1 >= d1.AddYears(-5));
		}
開發者ID:NaveinKumar,項目名稱:csharp-date,代碼行數:23,代碼來源:DateTests.cs


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