当前位置: 首页>>代码示例>>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;未经允许,请勿转载。