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


C# DateTime.CompareTo方法代码示例

本文整理汇总了C#中System.DateTime.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.CompareTo方法的具体用法?C# DateTime.CompareTo怎么用?C# DateTime.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


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

示例1: getBookingPeriod

 //This method returns period for given booking
 public MPeriod getBookingPeriod(MBatteryStorage storage, DateTime time)
 {
     List<MPeriod> periods = dbPeriod.getStoragePeriods(storage.id,true);
     MPeriod lastPeriod = periods[periods.Count - 1];
     if (time.CompareTo(lastPeriod.time) > 0)//if time of booking is later then time of last period
     {
         while (time.CompareTo(lastPeriod.time) > 0) //while time of booking is earlier or in the same time then time of last period
         {
             lastPeriod = createPeriod(storage);//create new period
         }
     }
     else //if time of booking is before time of last period
     {
         for (int x = periods.Count - 1; x >= 1; x--) //for periods from last to first
         {
             MPeriod next = periods[x]; //last created period
             MPeriod curr = periods[x - 1]; //second last period
             if ((time.CompareTo(curr.time) >= 0) & (time.CompareTo(next.time) < 0)) //if time of booking is later then current and earlier then next period
             {
                 return curr;
             }
         }
      }
     return lastPeriod;
 }
开发者ID:Dadov,项目名称:3rdsemproject,代码行数:26,代码来源:PeriodCalculator.cs

示例2: GetAllVisualRun

 public static IQueryable<BOLichBieuKhongDinhKy> GetAllVisualRun(KaraokeEntities kara,BAN ban)
 {
     int? khuID = ban == null ? null : ban.KhuID;
     DateTime dtNow = DateTime.Now;
     DateTime dt = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day);
     TimeSpan ts = new TimeSpan(dt.Hour, dt.Minute, dt.Second);
     var querya = BOMenuLoaiGia.GetAllVisual(kara);
     var queryb = from b in GetAllVisual(kara)
                  where
                      ts.CompareTo(b.GioBatDau.Value) >= 0 && ts.CompareTo(b.GioKetThuc.Value) <= 0 &&
                      dt.CompareTo(b.NgayBatDau.Value) >= 0 && dt.CompareTo(b.NgayKetThuc.Value) <= 0 &&
                      (
                         b.KhuID == null ||
                         b.KhuID == khuID
                      )
                  select b;
     var query = from a in querya
                 join b in queryb on a.LoaiGiaID equals b.LoaiGiaID
                 select new BOLichBieuKhongDinhKy
                 {
                     MenuLoaiGia = a,
                     LichBieuKhongDinhKy = b
                 };
     return query.Distinct();
 }
开发者ID:MisterTobi,项目名称:restaurant-cafe,代码行数:25,代码来源:BOLichBieuKhongDinhKy.cs

示例3: TableSorter

        public void TableSorter(List<String> lst)
        {
            int result = 0;
            Boolean b = false;
            DateTime d1 = new DateTime();
            DateTime d2 = new DateTime();
            for (int i = 1; i < lst.Count; i++)
            {
                d1 = Convert.ToDateTime(lst.ElementAt(i - 1));
                d2 = Convert.ToDateTime(lst.ElementAt(i));
                Console.WriteLine(d1);
                Console.WriteLine(d2);
                result = d1.CompareTo(d2);
                Console.WriteLine(result);
                if (result < 0)
                {
                    b = true;
                }
                else
                {
                    b = false;
                    break;
                }
            }
            if (b == true)
            {
                Console.WriteLine("Sorted ascending");
            }
            else
            {
                for (int i = 1; i < lst.Count; i++)
                {
                    d1 = Convert.ToDateTime(lst.ElementAt(i - 1));
                    d2 = Convert.ToDateTime(lst.ElementAt(i));
                    Console.WriteLine(d1);
                    Console.WriteLine(d2);
                    result = d1.CompareTo(d2);
                    Console.WriteLine(result);
                    if (result > 0)
                    {
                        b = true;
                    }
                    else
                    {
                        b = false;
                        Console.WriteLine("Not sorted");
                        break;
                    }
                }
                if (b == true)
                {
                    Console.WriteLine("Sorted descending");
                }

            }
        }
开发者ID:Denvergoa,项目名称:TableSorter,代码行数:56,代码来源:Sorter.cs

示例4: isInPeriod

 public bool isInPeriod(MPeriod period, DateTime time, MBatteryStorage storage)
 {
     DateTime first = period.time;
     double hours = (double) storage.type.capacity;
     DateTime second = period.time.AddHours(hours);
     if ((time.CompareTo(first) >= 0) & (time.CompareTo(second) < 0))
     {
         return true;
     }
     else return false;
 }
开发者ID:Dadov,项目名称:3rdsemproject,代码行数:11,代码来源:PeriodCalculatorTest.cs

示例5: ValidRelativeMonthYear

        internal static bool ValidRelativeMonthYear(MonthYear input,
                                                    int lowerBound, MonthYearUnit lowerUnit, RangeBoundaryType lowerBoundType,
                                                    int upperBound, MonthYearUnit upperUnit, RangeBoundaryType upperBoundType)
        {
            DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime lowerDate = DateTime.MinValue;
            DateTime upperDate = DateTime.MaxValue;
            DateTime inputDate = new DateTime(input.Year, input.Month, 1);

            switch (lowerUnit)
            {
                case MonthYearUnit.Month:
                    lowerDate = now.AddMonths(lowerBound * -1);
                    break;
                case MonthYearUnit.Year:
                    lowerDate = now.AddYears(lowerBound * -1);
                    break;
            }
            switch (upperUnit)
            {
                case MonthYearUnit.Month:
                    upperDate = now.AddMonths(upperBound);
                    break;
                case MonthYearUnit.Year:
                    upperDate = now.AddYears(upperBound);
                    break;
            }

            //default the bound check to true - if lowerBoundType is Ignore, no test will be performed.
            bool lowerBoundOk = true;
            if (lowerBoundType == RangeBoundaryType.Inclusive)
            {
                lowerBoundOk = inputDate.CompareTo(lowerDate) >= 0;
            }
            else if (lowerBoundType == RangeBoundaryType.Exclusive)
            {
                lowerBoundOk = inputDate.CompareTo(lowerDate) > 0;
            }

            //default the bound check to true - if upperBoundType is Ignore, no test will be performed.
            bool upperBoundOk = true;
            if (upperBoundType == RangeBoundaryType.Inclusive)
            {
                upperBoundOk = inputDate.CompareTo(upperDate) <= 0;
            }
            else if (upperBoundType == RangeBoundaryType.Exclusive)
            {
                upperBoundOk = inputDate.CompareTo(upperDate) < 0;
            }

            return lowerBoundOk && upperBoundOk;
        }
开发者ID:GrahamClark,项目名称:TestConsoleApp,代码行数:52,代码来源:Runner.cs

示例6: Validate_Date

        private static bool Validate_Date(DateTime date)
        {

            int compValue = date.CompareTo(DateTime.Now);
            // Print_To_Console(compValue.ToString());
            return (compValue < 0) ? true : false;
        }
开发者ID:krishnamohan-seelam,项目名称:CSharp-Examples,代码行数:7,代码来源:Program.cs

示例7: CheckWorkingDates

        private static void CheckWorkingDates(DateTime now, DateTime final, List<DateTime> holidays)
        {
            //got the length between without weekends or holidays
            int lengthDays = (final - now).Days;
            int length = lengthDays;
            DateTime currentDate = new DateTime();
            //check which dates of the period are weekends or holidays
            //and decrease the length
            //we pass through the whole period
            for (int i = 0; i <= length; i++)
            {
                //increase date
                currentDate = now.AddDays(i);
                //we compare the currentDate with every single holiday
                for (int days = 0; days < holidays.Count; days++)
                {
                    int comparison = currentDate.CompareTo(holidays[days]); //if match return 0
                    if (comparison == 0)
                    {
                        //decrease the length of period
                        lengthDays--;
                    }
                }
                //check is the current day in weekend
                if (currentDate.DayOfWeek == DayOfWeek.Saturday || currentDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    //decrease the length ot period
                    lengthDays--;
                }
            }

            PrintResult(now, final, lengthDays);
        }
开发者ID:prestress,项目名称:Telerik_Academy_Homework_Projects,代码行数:33,代码来源:05.cs

示例8: ToDo

 public ToDo(string message, DateTime deadline)
 {
     if (deadline.CompareTo(DateTime.Now) <= 0 && Environment.GetEnvironmentVariable("NDoByEnabled").Equals("1"))
     {
         throw new Exception("The following ToDo's deadline has passed: " + message);
     }
 }
开发者ID:ExistentialEnso,项目名称:NDoBy,代码行数:7,代码来源:ToDo.cs

示例9: EnterValidFutureDate

 //this method checks if the date entered by the user is correct
 //and if it is in the future
 static DateTime EnterValidFutureDate(DateTime todayDate)
 {
     while (true)
     {
         Console.Write("Enter a future date (day.month.year) : ");
         string futureDay = Console.ReadLine();
         DateTime futureDate;
         bool successParse = DateTime.TryParse(futureDay, out futureDate);
         if (successParse)
         {
             int compare = todayDate.CompareTo(futureDate);
             if (compare < 0)
             {
                 return futureDate;
             }
             else
             {
                 Console.WriteLine("The date must be in future!");
             }
         }
         else
         {
             Console.WriteLine("Wrong input!");
         }
     }
 }
开发者ID:novocob,项目名称:TelerikAcademy,代码行数:28,代码来源:NumberOfWorkDays.cs

示例10: GetAssetsLost

        public static EMMADataSet.AssetsLostDataTable GetAssetsLost(long ownerID, DateTime startDate, DateTime endDate)
        {
            EMMADataSet.AssetsLostDataTable retVal = new EMMADataSet.AssetsLostDataTable();

            if (startDate.CompareTo(SqlDateTime.MinValue.Value) < 0) startDate = SqlDateTime.MinValue.Value;
            if (endDate.CompareTo(SqlDateTime.MinValue.Value) < 0) endDate = SqlDateTime.MinValue.Value;
            if (startDate.CompareTo(SqlDateTime.MaxValue.Value) > 0) startDate = SqlDateTime.MaxValue.Value;
            if (endDate.CompareTo(SqlDateTime.MaxValue.Value) > 0) endDate = SqlDateTime.MaxValue.Value;

            lock (_tableAdapter)
            {
                _tableAdapter.FillByDate(retVal, ownerID, startDate, endDate);
            }

            return retVal;
        }
开发者ID:dedimarco,项目名称:evemarketmonitorapp,代码行数:16,代码来源:AssetsLost.cs

示例11: count

 static int count(DateTime date)
 {
     DateTime today = DateTime.Now;
     int count = -1;
     DateTime[] holidays = new DateTime[]
     {
         new DateTime(2015, 03, 03),
         new DateTime(2015, 04, 29),
         new DateTime(2015, 12, 25),
         // etc
     };
     Console.WriteLine("You are not working on the following holidays:");
     for (int i = 0; i < holidays.Length; i++)
     {
         Console.WriteLine(holidays[i].ToShortDateString());
     }
     while (date.CompareTo(today) > 0)
     {
         today = today.AddDays(1);
         if (today.DayOfWeek != DayOfWeek.Saturday && today.DayOfWeek != DayOfWeek.Sunday)
         {
             bool flag = true;
             for (int i = 0; i < holidays.Length; i++)
             {
                 if (today.Date == holidays[0].Date && today.Month == holidays[0].Month) flag = false;
             }
             if(flag != false)count++;
         }
     }
     return count;
 }
开发者ID:nenov,项目名称:CSharp_part2,代码行数:31,代码来源:Workdays.cs

示例12: Between

 /// <summary>
 /// 対象日が期間内かどうかのチェック
 /// </summary>
 /// <param name="date">対象日</param>
 /// <param name="longFrom">期間開始日</param>
 /// <param name="longTo">期間終了日</param>
 /// <returns>bool</returns>
 public static bool Between(this DateTime date, DateTime longFrom, DateTime longTo)
 {
     if (longTo.CompareTo(longFrom) < 0)
     {
         return false;
     }
     if (date.CompareTo(longFrom) < 0)
     {
         return false;
     }
     if (longTo.CompareTo(date) < 0)
     {
         return false;
     }
     return true;
 }
开发者ID:BGCX261,项目名称:zmw-dev-svn-to-git,代码行数:23,代码来源:DateTimeExtensions.cs

示例13: WorkingDays

 private static void WorkingDays(int days)
 {
     String yearsFur = furtherDate.ToString().Substring(6, 4);
     String yearNow = now.ToString().Substring(6, 4);
     PopulateFestivals(int.Parse(yearsFur) - int.Parse(yearNow) + 1, yearNow);
     DateTime curr = new DateTime();
     for (int i = 0; i < days; i++)
     {
         curr.AddDays(1);
         if (curr.DayOfWeek == DayOfWeek.Saturday || curr.DayOfWeek == DayOfWeek.Sunday) days--;
         else
         {
             for (int j = 0; j < int.Parse(yearsFur) - int.Parse(yearNow) + 1; j++)
             {
                 for (int t = 0; t < 4; t++)
                 {
                     if (curr.CompareTo(festivals[j, t]) == 0)
                     {
                         days--;
                         break;
                     }
                 }
             }
         }
     }
     Console.WriteLine("Working days : {0}",days);
 }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:27,代码来源:Program.cs

示例14: GetDate

        public void GetDate(DateTime sender)
        {
            if (this.DataSource == null) return;
            if (this.DataSource.Rows.Count == 0) return;

            try
            {
                DateTime time = sender;
                TimeSpan span = new TimeSpan(30, 0, 0, 0);
                TimeSpan span2 = span;
                DateTime time2 = sender.Subtract(span);
                DateTime time3 = sender.Add(span);
                for (int i = this.DataSource.Rows.Count - 1; i >= 0; i--)
                {
                    if (sender.CompareTo(Convert.ToDateTime(this.DataSource.Rows[i]["sun"])) >= 0)
                    {
                        this.Index = i;
                        DateTime time4 = new DateTime(sender.Year, sender.Month, sender.Day);
                        span2 = (TimeSpan)(time4 - Convert.ToDateTime(this.DataSource.Rows[this.Index]["sun"]));
                        time = Convert.ToDateTime(this.DataSource.Rows[this.Index]["date"]);
                        break;
                    }
                }
                this.year = time.Year;
                if (span2.Days <= 30)
                {
                    this.month = time.Month;
                    this.day = span2.Days + 1;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }
开发者ID:nilmarpublio,项目名称:jawiweb,代码行数:35,代码来源:MuslimCalendar.cs

示例15: WorkingDays

    static int WorkingDays(DateTime dateNow, DateTime endDate)
    {
        // Calculating the difference in days between the two dates and thi will give us
        // how many times to run the for cycle
        int daysLenght = Math.Abs((dateNow-endDate).Days);

        // Assigning this value to the counter
        int counter = daysLenght;

        for (int i = 0; i < daysLenght; i++)
        {
            // every time we add 1 day
            dateNow = dateNow.AddDays(1);

            // checking if this date is Saturday or Sunday and substract it
            if (dateNow.DayOfWeek == DayOfWeek.Saturday || dateNow.DayOfWeek == DayOfWeek.Sunday)
            {
            counter--;
            }

            // going thru all Holidays and if there is a match -> substracting one day
            for (int days = 0; days < Holidays.Length; days++)
            {
                if (dateNow.CompareTo(Holidays[days]) == 0)
                {
                    counter--;
                }
            }
        }

        return counter; // final result
    }
开发者ID:tddold,项目名称:TelerikAcademyHomework,代码行数:32,代码来源:Workdays.cs


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