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


C# TimeSpan.CompareTo方法代码示例

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


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

示例1: StartService

        /// <summary>
        /// Start the service with the given name and wait until the status of the service is running.
        /// If the service status is not running after the given timeout then the service is considered not started.
        /// You can call this method after stop or pause the service in order to re-start it.
        /// </summary>
        /// <param name="serviceName">The name of the service</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>True if the service has been started. Otherwise, false.</returns>
        public static bool StartService(string serviceName, TimeSpan timeout)
        {
            try
            {
                bool timeoutEnabled = (timeout.CompareTo(TimeSpan.Zero) > 0);
                using (ServiceController c = new ServiceController(serviceName))
                {
                    c.Refresh();
                    if (timeoutEnabled && c.Status == ServiceControllerStatus.Running)
                        return true;
                    if (!timeoutEnabled && (c.Status == ServiceControllerStatus.Running || c.Status == ServiceControllerStatus.StartPending || c.Status == ServiceControllerStatus.ContinuePending))
                        return true;

                    if (c.Status == ServiceControllerStatus.Paused || c.Status == ServiceControllerStatus.ContinuePending)
                        c.Continue();
                    else if (c.Status == ServiceControllerStatus.Stopped || c.Status == ServiceControllerStatus.StartPending)
                        c.Start();
                    if (timeoutEnabled)
                        c.WaitForStatus(ServiceControllerStatus.Running, timeout);
                    return true;
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error starting service {0}.", serviceName);
                return false;
            }
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:36,代码来源:ServiceManager.cs

示例2: EvaluateExpirationParameters

        public static byte EvaluateExpirationParameters(DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            if(Web.Caching.Cache.NoAbsoluteExpiration.Equals(absoluteExpiration) &&
                Web.Caching.Cache.NoSlidingExpiration.Equals(slidingExpiration))
            {
                return 2;
            }

            if(Web.Caching.Cache.NoAbsoluteExpiration.Equals(absoluteExpiration))
            {
                if(slidingExpiration.CompareTo(TimeSpan.Zero) < 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");

                if(slidingExpiration.CompareTo(DateTime.Now.AddYears(1) - DateTime.Now) >= 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");

                return 0;
            }

            if(Web.Caching.Cache.NoSlidingExpiration.Equals(slidingExpiration))
            {
                return 1;
            }

            throw new ArgumentException("You cannot set both sliding and absolute expirations on the same cache item.");
        }
开发者ID:javithalion,项目名称:NCache,代码行数:26,代码来源:WebCacheHelper.cs

示例3: 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

示例4: CompareToWorks

		public void CompareToWorks() {
			var time1 = new TimeSpan(15, 10, 20, 5, 14);
			var time2 = new TimeSpan(14, 10, 20, 5, 14);
			var time3 = new TimeSpan(15, 11, 20, 5, 14);
			Assert.AreEqual(0, time1.CompareTo(time1));
			Assert.AreEqual(1, time1.CompareTo(time2));
			Assert.AreEqual(-1, time1.CompareTo(time3));
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:8,代码来源:TimeSpanTests.cs

示例5: GetVacationName

 private static string GetVacationName(DateTime h)
 {
     TimeSpan t = new TimeSpan(h.Hour, h.Minute, h.Second);
     if (t.CompareTo(new TimeSpan(7, 30, 00)) >= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) < 0) //t plus grand que 7h30  et t plus petit que 19h30 alors vac jour
     {
         return "Jour";
     }
     else
     {
         return "Nuit";
     }
 }
开发者ID:0ups,项目名称:dOnuts-InterfaceTablette,代码行数:12,代码来源:UC_WIDGET_Verifications.xaml.cs

示例6: PrettyDeltaTime

        public static string PrettyDeltaTime(TimeSpan span, string rough = "")
        {
            int day = Convert.ToInt32(span.ToString("%d"));
              int hour = Convert.ToInt32(span.ToString("%h"));
              int minute = Convert.ToInt32(span.ToString("%m"));

              if (span.CompareTo(TimeSpan.Zero) == -1) {
            Log($"Time to sync the clock?{span}", ConsoleColor.Red);
            return "a few seconds";
              }

              if (day > 1) {
            if (hour == 0) return $"{day} days";
            return $"{day} days {hour}h";
              }

              if (day == 1) {
            if (hour == 0) return "1 day";
            return $"1 day {hour}h";
              }

              if (hour == 0) return $"{rough}{minute}m";
              if (minute == 0) return $"{rough}{hour}h";

              return $"{rough}{hour}h {minute}m";
        }
开发者ID:destinygg,项目名称:bot,代码行数:26,代码来源:Tools.cs

示例7: OffsetToString

 public static string OffsetToString(TimeSpan aTimeSpan)
 {
     string sign = aTimeSpan.CompareTo(TimeSpan.Zero) >= 0 ? "+" : "-";
     string hours = Math.Abs(aTimeSpan.Hours).ToString();
     string minutes = Math.Abs(aTimeSpan.Minutes).ToString("00");
     return sign + hours + ":" + minutes;
 }
开发者ID:weeble,项目名称:ohos,代码行数:7,代码来源:TimeZoneSerializer.cs

示例8: MakeExpirationHint

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ticks"></param>
        /// <param name="isSliding"></param>
        /// <returns></returns>
        public static ExpirationHint MakeExpirationHint(long ticks, bool isAbsolute)
        {
            if (ticks == 0) return null;

            if (!isAbsolute)
            {
                TimeSpan slidingExpiration = new TimeSpan(ticks);
                if (slidingExpiration.CompareTo(TimeSpan.Zero) < 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                if (slidingExpiration.CompareTo(DateTime.Now.AddYears(1) - DateTime.Now) >= 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                return new IdleExpiration(slidingExpiration);
            }
            else
            {
                DateTime absoluteExpiration = new DateTime(ticks, DateTimeKind.Utc);
                return new FixedExpiration(absoluteExpiration);
            }
        }
开发者ID:javithalion,项目名称:NCache,代码行数:25,代码来源:ConvHelper.cs

示例9: GetHeureLimiteVacation

        public static DateTime GetHeureLimiteVacation(string borne)
        {
            TimeSpan t = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            if (t.CompareTo(new TimeSpan(7, 30, 00)) >= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) < 0) //Vac jour?
            {
                if (borne == "début")
                {
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 00);
                }
                else
                {
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 30, 00);
                }
            }
            else
            {

                if (t.CompareTo(new TimeSpan(23, 59, 59)) <= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) >= 0) //S'il est avant ou égale à 23h59:59 --> alors on est le soir
                {
                    if (borne == "début")
                    {
                        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 30, 00);
                    }
                    else
                    {
                        return new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day, 7, 30, 00);
                    }
                }
                else
                {
                    if (borne == "début")
                    {
                        return new DateTime(DateTime.Now.AddDays(-1).Year, DateTime.Now.AddDays(-1).Month, DateTime.Now.AddDays(-1).Day, 19, 30, 00);
                    }
                    else
                    {
                        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 00);
                    }
                }

            }
        }
开发者ID:0ups,项目名称:dOnuts-InterfaceTablette,代码行数:42,代码来源:UC_WIDGET_TimelinePresentation.xaml.cs

示例10: CreateAlarm

 //TODO: Recurring
 public void CreateAlarm(string ID, DateTime dt, TimeSpan recurring)
 {
     Form1.updateLog("Creating timer for: " + dt.ToShortTimeString(), ELogLevel.Info,
         ELogType.AlarmClock);
     TimeSpan ts = dt - DateTime.Now;
     bool isRecurring = (recurring!=null && recurring.CompareTo(zero)!=0);
     Timer t = new Timer(new TimerCallback(Tick), ID, ts, recurring);
     lock(timers){
         timers.Add(ID, new Tuple<Timer, bool>(t, isRecurring));
     }
 }
开发者ID:kingtut666,项目名称:holly,代码行数:12,代码来源:AlarmClock.cs

示例11: update

 public void update(GameTime time)
 {
     if (!stopped)
     {
         elapsed += time.ElapsedGameTime;
         if (elapsed.CompareTo(interval) >= 0)
         {
             fire();
             elapsed = new TimeSpan();
         }
     }
 }
开发者ID:ebshimizu,项目名称:Parchment-Dragon,代码行数:12,代码来源:fireTimer.cs

示例12: Update

 protected override void Update(GameTime gameTime)
 {
     frame += gameTime.ElapsedGameTime;
     if (frame.CompareTo(new  TimeSpan(0, 0, 0,0 ,30)) == 1)
     {
         Debug.Print(frame.TotalMilliseconds + "");
         frame = new TimeSpan();
         printFrame = true;
         StateManager.CurrentState.Update();
         base.Update(gameTime);
     }
 }
开发者ID:titanXL,项目名称:SoftwareUniversity,代码行数:12,代码来源:UnSeriousEngine.cs

示例13: UpdateSprite

        public void UpdateSprite(GameTime gameTime, GraphicsDeviceManager graphics)
        {
            if (!alive) return;
            // Move the sprite by speed, scaled by elapsed time.
            DateTime a = DateTime.Now;

            timeToLive=timeToLive.Subtract(gameTime.ElapsedGameTime);
            if (timeToLive.CompareTo(TimeSpan.Zero) < 0)
            {
                alive = false;
            }

            blend = (float)timeToLive.TotalMilliseconds / 500;
            scale = (1000-(float)timeToLive.TotalMilliseconds)/1000;
        }
开发者ID:kenpower,项目名称:XNA4,代码行数:15,代码来源:Game1.cs

示例14:

 public float 取平均值(float d, int t)
 {
     span = System.DateTime.Now - 基点时间;
     int 比较值 = span.CompareTo(比较时间戳);
     if (比较值 > 0)
     {
         基点时间 = System.DateTime.Now;
         平均值 = (d + 平均值) / 2;
         return 平均值;
     }
     else
     {
         平均值 = (d + 平均值) / 2;
         return -1;
     }
 }
开发者ID:jyorin,项目名称:yinghe,代码行数:16,代码来源:数据项接口.cs

示例15: horarioComercial

        public void horarioComercial()
        {
            TimeSpan inicio = new TimeSpan(07, 50, 0);
            TimeSpan final = new TimeSpan(17, 10, 0);
            TimeSpan puts = DateTime.Now - DateTime.Now.Date;
            TimeSpan agora = new TimeSpan(puts.Hours, puts.Minutes, puts.Seconds);

            if (inicio.CompareTo(agora) == 1)
            {
                MessageBox.Show("O sistema funciona somente em horário comercial: 08:00h às 17:00h !", "Fora do horário comercial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
            if (final.CompareTo(agora) == -1)
            {
                MessageBox.Show("O sistema funciona somente em horário comercial: 08:00h às 17:00h !", "Fora do horário comercial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }
开发者ID:vinidg,项目名称:sistema-solicitacao-prontuarios,代码行数:18,代码来源:Menu.cs


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