protected void Page_Load(object sender, EventArgs e) { HyLonginLog hyLonginLog = new HyLonginLog(); DataTable dt = hyLonginLog.GetDataTableAllOnLine(); if (dt.Rows.Count > 0) { DateTime t1 = new DateTime(); DateTime t2 = DateTime.Now; DateTime t3 = new DateTime(); double diff = 0; double onlineTimeTotal = 0; for (int i = 0; i < dt.Rows.Count; i++) { t1 = Convert.ToDateTime(dt.Rows[i]["hyUpateTime"].ToString()); t3 = Convert.ToDateTime(dt.Rows[i]["hyLoginTime"].ToString()); TimeSpan tt1 = new TimeSpan(t1.Ticks); TimeSpan tt2 = new TimeSpan(t2.Ticks); TimeSpan tt3 = new TimeSpan(t3.Ticks); diff = Convert.ToDouble(tt2.Subtract(tt1).TotalMinutes.ToString()); onlineTimeTotal = Convert.ToDouble(tt2.Subtract(tt3).TotalMinutes.ToString()); if (diff >= 10) { hyLonginLog.id = dt.Rows[i]["id"].ToString(); hyLonginLog.hyLogoutTime = DateTime.Now.ToString(); hyLonginLog.hyNotOnLine = "1"; hyLonginLog.hyonlineTimeTotal = onlineTimeTotal.ToString("0.00"); hyLonginLog.UpdateLogOutTime(); } } } }
private static void PrintDayStats(IReadOnlyList<DateTime> dates) { var totalMinutesIn = new TimeSpan(0, 0, 0, 0); var totalMinutesOut = new TimeSpan(0, 0, 0, 0); DateTime lastDate = dates[0]; var isIn = false; for (int i = 1; i < dates.Count; i++) { var instance = dates[i]; isIn = !isIn; if (isIn) { totalMinutesIn = totalMinutesIn.Add(instance.Subtract(lastDate)); } else { totalMinutesOut = totalMinutesOut.Add(instance.Subtract(lastDate)); } lastDate = instance; } Console.WriteLine("Total minutes in: {0}, out: {1}, extra: {2}", totalMinutesIn, totalMinutesOut, totalMinutesIn.Subtract(Day)); _overtime = _overtime.Add(totalMinutesIn.Subtract(Day)); }
public void Draw(SpriteBatch sb, int xlocation, TimeSpan currentTime) { if (!visible) return; int stretch = 0; float fadeOutAmt = 1.0f; if (completed) { stretch = (int)(currentTime.Subtract(compSpan).TotalMilliseconds / 5); //magic numbers: 500 milliseconds to grow 50 pixels fadeOutAmt = Math.Max((50.0f - stretch) / 50.0f , 0.0f); //scoreColor.A = (byte)Math.Max((125 * fadeOutAmt), 0); //scoreColor = scoreColor * Math.Max(fadeOutAmt, 0); if (stretch > 50) { visible = false; return; } } double fadeIn = currentTime.Subtract(moveSpan).TotalMilliseconds + 1200.0f; if (fadeIn < 0) fadeOutAmt = (float)(800.0f + fadeIn) / 800.0f; //magic numbers! if (GetMoveIcon() != null) sb.Draw(GetMoveIcon(), new Rectangle(xlocation - stretch, GLOBALS.WINDOW_HEIGHT - (160 + stretch), 120 + (2 * stretch), GLOBALS.WINDOW_HEIGHT - (350 - (2 * stretch))), scoreColor * fadeOutAmt); }
public static string getRemainingTime() { System.TimeSpan t = regenerationTime.Subtract(diff); string timeText = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds); return(timeText); }
/// <summary> /// Get the notifications for the nex 15 minutes /// </summary> async Task GetUpcomingNotifications() { try { var client = new BMAStaticDataService.StaticClient(); var result = await client.GetUpcomingNotificationsAsync(DateTime.Now); if (result.Count == 0) return; List<int> durationList = new List<int>(); foreach (var item in result) { TimeSpan ts1 = new TimeSpan(item.Time.Hour, item.Time.Minute, 0); TimeSpan ts2 = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0); int duration = Convert.ToInt32(Math.Round(ts1.Subtract(ts2).Duration().TotalMinutes, MidpointRounding.AwayFromZero)); durationList.Add(duration); } if (durationList.Count() > 0) { ShowNotification(durationList); SetupTiles(durationList); } } catch (Exception) { throw; } }
/// <summary> /// 当天剩余秒数 /// </summary> /// <returns></returns> public static int SecondsRemainingDay() { var ts1=new TimeSpan(DateTime.Now.Ticks); var ts2 = new TimeSpan(DateTime.Now.AddDays(1).Date.Ticks); var ts = ts1.Subtract(ts2).Duration(); return ts.TotalSeconds.To<int>()-1; }
IEnumerator TiliRecoverCorou() { while (!destroyed) { System.TimeSpan ts1 = new System.TimeSpan(System.DateTime.Now.Ticks); System.TimeSpan ts2 = new System.TimeSpan(System.Convert.ToDateTime(SettingManager.Instance.TiliRecoverTime).Ticks); System.TimeSpan ts = ts1.Subtract(ts2).Duration(); int count = (int)(ts.TotalSeconds) / recoverDuration; int remained = (int)(ts.TotalSeconds) % recoverDuration; count = SettingManager.Instance.TotalTili + count; SettingManager.Instance.TotalTili = Mathf.Min(20, count); if (SettingManager.Instance.TotalTili >= 20) { tiliRemained.gameObject.SetActive(false); EventService.Instance.GetEvent <TiliChangeEvent>().Publish(SettingManager.Instance.TotalTili); break; } else { tiliRemained.gameObject.SetActive(true); tiliRemained.text = Ultilities.ConvertSecondToTime(recoverDuration - remained); if (remained <= 0) { SettingManager.Instance.TotalTili += 1; EventService.Instance.GetEvent <TiliChangeEvent>().Publish(SettingManager.Instance.TotalTili); } } yield return(new WaitForSeconds(1)); } }
/// <summary> /// 获取当前登录用户 /// </summary> protected SysUser GetUser() { SysUser sessionUser = Session["SysUser"] as SysUser; if (sessionUser == null) { if (String.IsNullOrEmpty(User.Identity.Name)) { return null; } else { FormsIdentity identity = User.Identity as FormsIdentity; saveUserToSession(identity.Name, identity.Ticket.UserData); } } else { TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts2 = new TimeSpan(sessionUser.LastActiveTime.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); int min = ts.Minutes; if (min > 20) { // 可配置项 // 超过20分钟不活跃,则跳转到登录页 return null; } else { sessionUser.LastActiveTime = DateTime.Now; Session["SysUser"] = sessionUser; } } return Session["SysUser"] as SysUser; }
static void Main(string[] args) { //微软MSMQ消息队列与WCF离线操作 //HTTP NetMsmqBinding_IWCFMSMQService WCFMSMQServiceClient wcfServiceProxy = new WCFMSMQServiceClient("NetMsmqBinding_IWCFMSMQService"); //通过代理调用SayHello服务,这里及时服务调用服务失败,消息会发送到队列里进行缓存。 TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); for (int i = 0; i < 100000; i++) { Console.WriteLine("xiaopotian"); wcfServiceProxy.SayHelloMSMQ("xiaopotian"); } TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts2.Subtract(ts1).Duration(); //string a = ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒"; Console.WriteLine(ts.Milliseconds); //Thread.Sleep(2000);//客户端休眠两秒,继续下一次调用 //Console.WriteLine("WCF 2 Call at:{0}", DateTime.Now); //wcfServiceProxy.SayHelloMSMQ("Frank Xu"); //Thread.Sleep(2000);//客户端休眠两秒,继续下一次调用 //Console.WriteLine("WCF 3 Call at:{0}", DateTime.Now); //wcfServiceProxy.SayHelloMSMQ("Frank Xu Lei"); //For Debug Console.WriteLine("Press any key to continue"); Console.Read(); }
public static IEnumerator GetRequest(string url, object ud, int tag, INetCallback callback, IHttpCallback httpCallback, bool showLoading) { DateTime start = DateTime.Now; HttpPackage hp = new HttpPackage(); hp.w = new WWW(url); hp.Tag = tag; hp.FuncCallback = callback; if (RequestNotify != null && showLoading) { RequestNotify(Net.Status.eStartRequest); } yield return hp.w; if (RequestNotify != null && showLoading) { RequestNotify(Net.Status.eEndRequest); } if(null != httpCallback) { TimeSpan tsStart = new TimeSpan(start.Ticks); TimeSpan tsEnd = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = tsEnd.Subtract(tsStart).Duration(); if(ts.Seconds > OVER_TIME) { hp.overTime = true; } httpCallback.OnHttpRespond(hp, ud); } else { Debug.Log("no http callback"); } }
public void Delay() { //delay to test (3 seconds) var delay = new TimeSpan(0, 0, 0, 3 /* seconds */); //tollerance (actual time should be between 2.9 and 3.1 seconds) var tollerance = new TimeSpan(0, 0, 0, 0, 100 /* milliseconds */); Stopwatch stopwatch = new Stopwatch(); Timer timer = new Timer(); Loop.Current.QueueWork(() => { stopwatch.Start(); timer.Start(delay, TimeSpan.Zero, () => { stopwatch.Stop(); timer.Stop(); timer.Close(); }); }); Loop.Current.Run(); Assert.GreaterOrEqual(stopwatch.Elapsed, delay.Subtract(tollerance)); Assert.Less(stopwatch.Elapsed, delay.Add(tollerance)); }
public static string GetStatusPic(object Status, object TJDate, object Path) { if (Status.ToString() == "70") { if (TJDate.ToString() != "") { DateTime dtNow = DateTime.Now; DateTime dtTJ = DateTime.Parse(TJDate.ToString()); //看时间,超过2天,黄灯,超过3天红灯 TimeSpan tsNow = new TimeSpan(dtNow.Ticks); TimeSpan tsTJ = new TimeSpan(dtTJ.Ticks); TimeSpan ts = tsNow.Subtract(tsTJ).Duration(); if (ts.Days >= 3) { return "<img src='"+ Path + "/Images/redLight.gif' />"; } else if (ts.Days >= 2) { return "<img src='" + Path + "/Images/yellowLight.gif' />"; } return ""; } return ""; } return ""; }
public string DateCompare(string beginDate, string endDate) { try { if (beginDate != null && endDate != null) { DateTime ed=Convert.ToDateTime(endDate); DateTime bd = Convert.ToDateTime(beginDate); //TimeSpan dt = Convert.ToDateTime(endDate) - Convert.ToDateTime(beginDate); //return dt.ToString(); string dateDiff = null; TimeSpan ts1 = new TimeSpan(ed.Ticks); TimeSpan ts2 = new TimeSpan(bd.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); dateDiff =ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString(); return dateDiff; } else { return ""; } } catch (Exception ex) { return ""; } }
/// <summary> /// 程序执行时间测试 /// </summary> /// <param name="dateBegin">开始时间</param> /// <param name="dateEnd">结束时间</param> /// <returns>返回(秒)单位,比如: 0.00239秒</returns> public static string ExecDateDiff(DateTime dateBegin, DateTime dateEnd) { TimeSpan ts1 = new TimeSpan(dateBegin.Ticks); TimeSpan ts2 = new TimeSpan(dateEnd.Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); return ts3.TotalMilliseconds.ToString(); }
/// <summary> /// 时间差值 /// </summary> /// <param name="dateTime1">比较时间1</param> /// <param name="dateTime2">比较时间2</param> /// <returns>返回相差的TimeSpan</returns> public static TimeSpan DateDiff(DateTime dateTime1, DateTime dateTime2) { TimeSpan ts1 = new TimeSpan(dateTime1.Ticks); TimeSpan ts2 = new TimeSpan(dateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); return ts; }
static void Main(string[] args) { //Creating Timespan var timeSpan = new System.TimeSpan(1, 2, 3); var timeSpan1 = new System.TimeSpan(1, 0, 0); var timeSpan2 = System.TimeSpan.FromHours(1); var start = DateTime.Now; var end = DateTime.Now.AddMinutes(2); var duration = end - start; Console.WriteLine("Duration: " + duration); //Properties Console.WriteLine("Minutes: " + timeSpan.Minutes); Console.WriteLine("Total Minutes: " + timeSpan.TotalMinutes); //Add Console.WriteLine("Add Example: " + timeSpan.Add(System.TimeSpan.FromMinutes(8))); Console.WriteLine("Subtract Example: " + timeSpan.Subtract(System.TimeSpan.FromMinutes(2))); // ToString Console.WriteLine("ToString " + timeSpan.ToString()); // Parse Console.WriteLine("Parse: " + System.TimeSpan.Parse("01:02:03")); }
public Point Run(TimeSpan duration) { AnimationCueDirectionEnum dir = _currentCue.Next; // if this is the case then we never have to do time calcs if (dir == AnimationCueDirectionEnum.StayHere) { _isEnd = true; return _currentCue.Point; } while (duration.Ticks >= _remainingTimeAtThisCue.Ticks) { duration = duration.Subtract(_remainingTimeAtThisCue); // move to next if (dir == AnimationCueDirectionEnum.MoveToNext) { AnimationCue cue = _subject.GetNextCue(_currentCue); _currentCue = cue; } else if (dir == AnimationCueDirectionEnum.MoveToBeginning) { _currentCue = _subject.First; } _remainingTimeAtThisCue = _currentCue.Duration; dir = _currentCue.Next; } _remainingTimeAtThisCue = _remainingTimeAtThisCue.Subtract(duration); return _currentCue.Point; }
public void Update(TimeSpan total) { total = total.Subtract(Map01.start); if (total.Ticks < 0) total = total.Negate(); time = total.Minutes + ":" + total.Seconds.ToString("00.") + ":" + total.Milliseconds; }
public virtual float ApplyVelocity(TimeSpan from, TimeSpan to, TimeSpan totalDuration, float totalDistance) { if (from > totalDuration) { while (from > totalDuration) { from = from.Subtract(totalDuration); to = to.Subtract(totalDuration); } } else { if (to > totalDuration) to = totalDuration; } double scaleTime = ((double)totalDuration.TotalSeconds / (Right - Left)); float scaleDistance = totalDistance / (float)Area; double l = Left + (double)from.TotalSeconds / scaleTime; double r = Left + (double)to.TotalSeconds / scaleTime; double distance = Integral(l, r); float deltaDistance = scaleDistance * (float)distance; return deltaDistance; }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null); string message = "xiaopotian"; var body = Encoding.UTF8.GetBytes(message); TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); for (int i = 0; i < 100000; i++) { channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body); Console.WriteLine("xiaopotian"); } TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts2.Subtract(ts1).Duration(); Console.WriteLine(ts.TotalMilliseconds); } Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); }
public override void Update(GameTime gameTime) { base.Update(gameTime); elapsedTime = elapsedTime.Add(gameTime.ElapsedGameTime); while (elapsedTime > tick) { elapsedTime = elapsedTime.Subtract(tick); // TODO: If we're in single player, generate a "rain" tile every tick // Old code: /* for (int x = (int)(Terraria.Main.screenPosition.X / 16) - 100; x < (Terraria.Main.screenPosition.X / 16) + (Terraria.Main.screenWidth / 16) + 100; x++) { if (x >= 0 && x <= Terraria.Main.maxTilesX && random.Next(200) == 0) { if (Terraria.Main.tile[x, y] == null) Terraria.Main.tile[x, y] = new Terraria.Tile(); Terraria.Main.tile[x, y].liquid = (byte)random.Next(8); Terraria.Main.tile[x, y].lava = true; Terraria.Liquid.AddWater(x, y); } } */ } }
protected void Page_Load(object sender, EventArgs e) { string htmlstring = ""; News spfNews = new News(); int RecordCount = spfNews.LoadSpfNews(); if (RecordCount > 0) { for (int i = 0; i < RecordCount; ++i) { TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts2 = new TimeSpan(spfNews.SpfNews[i].updateTime.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); // string strA = null; // if ( ts.Days/365 > 0 ) strA = (ts.Days/365).ToString() + " 年之前"; // else // { // if ( ts.Days/30 > 0 ) strA = (ts.Days/30).ToString() + " 月之前"; // else // { // if ( ts.Days > 0 ) strA = ts.Days.ToString() + " 天之前"; // else // { // if ( ts.Hours > 0 ) strA = ts.Hours.ToString() + " 小时之前"; // else // { // if ( ts.Minutes > 0 ) strA = ts.Minutes.ToString() + " 分钟之前"; // else // { // if ( ts.Seconds > 0 ) strA = ts.Seconds.ToString() + " 秒之前"; // } // } // } // } // } //string strB = Function.getDateTimeLaterThan(spfNews.SpfNews[i].updateTime.Ticks); htmlstring += "<div class=\"art-post post-94269 post type-post status-publish format-standard hentry category-camera-lens tag-canon tag-ebay\">\n" + "<div class=\"art-post-body\">\n" + "<div class=\"art-post-inner art-article\">\n" + "<div class=\"updatetime\">发布在 " + Function.getDateTimeLaterThan(spfNews.SpfNews[i].updateTime) + "</div>\n" + "<div class=\"art-article-up\">\n" + "<h2 class=\"art-postheader\">" + (i+1).ToString() + ". " + spfNews.SpfNews[i].newsTitle + "</h2>\n" + "<div class=\"art-postcontent\">\n" + spfNews.SpfNews[i].newsContent + "</div>\n" + "</div>\n" + "<div class=\"cleared\"></div>\n" + "</div>\n" + "<div class=\"cleared\"></div>\n" + "</div>\n" + "</div>\n"; } } else htmlstring += "●暂无信息\n"; this.div_post.InnerHtml = htmlstring; }
private bool decidetime() { TimeSpan ts1 = new TimeSpan(dtpDate.Value.Ticks); TimeSpan ts2 = new TimeSpan(dtpDate1.Value.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); if ((int)ts.Days > 31) { MessageBox.Show("跨月查询不能多于三十一天!", "提示", MessageBoxButtons.OK); return false; } if ((dtpDate.Value.AddYears(1).Year == dtpDate1.Value.Year || dtpDate.Value.Year == dtpDate1.Value.Year) && ((dtpDate.Value.Month == dtpDate1.Value.Month) || (dtpDate.Value.AddMonths(1).Month == dtpDate1.Value.Month))) { } else { MessageBox.Show("不能跨多月份查询!", "提示", MessageBoxButtons.OK); return false; } if ((int)ts.Days > 31) { MessageBox.Show("跨月查询不能多于三十一天!", "提示", MessageBoxButtons.OK); return false; } if (Convert.ToDateTime(dtpDate1.Value) > DateTime.Now) { dtpDate1.Value = DateTime.Now; } if (Convert.ToDateTime(dtpDate.Value).Date > Convert.ToDateTime(dtpDate1.Value).Date) { MessageBox.Show("开始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return false; } return true; }
public virtual Vector2 ApplyVelocity(TimeSpan from, TimeSpan to, TimeSpan totalDuration, Vector2 totalDistance) { if (from > totalDuration) { while (from > totalDuration) { from = from.Subtract(totalDuration); to = to.Subtract(totalDuration); } } else { if (to > totalDuration) to = totalDuration; } double scaleTime = ((double)totalDuration.TotalSeconds / (Right - Left)); Vector2 scaleDistance = Vector2.Divide(totalDistance, (float)Area); double l = Left+(double)from.TotalSeconds / scaleTime; double r = Left+(double)to.TotalSeconds / scaleTime; double distance = Integral(l, r); Vector2 deltaDistance = Vector2.Multiply(scaleDistance, (float)distance); return deltaDistance; }
private void detectCompression(float currentShoulderY) { IntervalObject tmpAnnotation; if (currentShoulderY < previousShoulderY && Math.Abs(currentShoulderY - previousShoulderY) > movingThreshold) { if (goingDown == false) { goingDown = true; goingUp = false; CompressionStarted = true; startCompression = DateTime.Now.Subtract(startRecordingTime).Subtract(TimeSpan.FromMilliseconds(35)); } } else if (currentShoulderY > previousShoulderY && Math.Abs(currentShoulderY - previousShoulderY) > movingThreshold) { goingUp = true; goingDown = false; } else if (currentShoulderY > previousShoulderY && Math.Abs(currentShoulderY - previousShoulderY) < movingThreshold) { if (goingUp && CompressionStarted) { endCompression = DateTime.Now.Subtract(startRecordingTime); double timeDifference = endCompression.Subtract(startCompression).TotalSeconds; //Console.WriteLine("timeDifference: " + timeDifference); goingUp = false; goingDown = false; CompressionStarted = false; endCompression = DateTime.Now.Subtract(startRecordingTime); tmpAnnotation = new IntervalObject(startCompression, endCompression); if (timeDifference < ccMaxDuration) { // if it doesn't contain the item tem if (!detectedCompressions.Intervals.Contains(tmpAnnotation)) { detectedCompressions.Intervals.Add(tmpAnnotation); compressionCounter++; lastCompression = tmpAnnotation; } } } } Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { if (goingDown == true) { compressionLabel.Content = "c.c. #" + compressionCounter + " down"; } else { compressionLabel.Content = "c.c. #" + compressionCounter + " up"; } })); previousShoulderY = currentShoulderY; }
/// <summary> /// 计算时间截差值 秒 /// </summary> /// <param name="ticks"></param> /// <returns></returns> public static int CalculatingDifferenceTicksSecond(long ticks) { var ts1 = new TimeSpan(DateTime.Now.Ticks); var ts2 = new TimeSpan(ticks); var ts = ts2.Subtract(ts1).Duration(); return ts.TotalSeconds.To<int>(); }
public int GetMillisecondsToEndDay(TimeSpan appenedTime, DateTime currentTime) { TimeSpan timeSpan = new TimeSpan(1, 0, 0, 0).Add(appenedTime); var curTimeSpan = new TimeSpan(0, currentTime.Hour, currentTime.Minute, currentTime.Second); TimeSpan remainingTime = timeSpan.Subtract(curTimeSpan); return (int)remainingTime.TotalMilliseconds; }
object ICache.Get(string key) { TimeSpan ts = new TimeSpan(DateTime.Now.Ticks); object obj2 = HttpRuntime.Cache.Get(key); TimeSpan span2 = new TimeSpan(DateTime.Now.Ticks); Log.Write(LogAction.Get, string.Concat(new object[] { "APICache.Get:t2-t1=", span2.Subtract(ts).Milliseconds, " :key=", key })); return obj2; }
public double ExecTimeDiff(DateTime dateBegin, DateTime dateEnd) { TimeSpan ts1 = new TimeSpan(dateBegin.Ticks); TimeSpan ts2 = new TimeSpan(dateEnd.Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); //你想转的格式 return ts3.TotalMilliseconds; }
private static TimeSpan DateDiff(DateTime dateTime1, DateTime dateTime2) { var ts1 = new TimeSpan(dateTime1.Ticks); var ts2 = new TimeSpan(dateTime2.Ticks); var ts = ts1.Subtract(ts2).Duration(); return ts; }
/// <summary> /// 获取留言时间 /// </summary> /// <param name="liuYanTime"></param> /// <returns></returns> protected string GetLiuYanTime(object liuYanTime) { if (liuYanTime == null) return string.Empty; var _liuYanTime = (DateTime)liuYanTime; TimeSpan ts1 = new TimeSpan(_liuYanTime.Ticks); TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts3 = ts2.Subtract(ts1).Duration(); var minutes = ts3.TotalMinutes; if (minutes <= 1) { return "1分钟前"; } else if (minutes <= 3) { return "3分钟前"; } else if (minutes <= 15) { return "15分钟前"; } else if (minutes <= 30) { return "30分钟前"; } else if (minutes <= 60) { return "1小时前"; } else if (minutes <= 120) { return "2小时前"; } else if (minutes <= 180) { return "3小时前"; } else if (minutes <= 360) { return "6小时前"; } else if (minutes <= 1440) { return "1天前"; } else if (minutes <= 2880) { return "2天前"; } else if (minutes <= 10080) { return "1星期前"; } return _liuYanTime.ToString("yyyy-MM-dd"); }
private string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = null; TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); dateDiff = "通話時間共:<span style=color:red>" + (int.Parse(ts.Days.ToString()) * 1440 + int.Parse(ts.Hours.ToString()) * 60 + int.Parse(ts.Minutes.ToString())).ToString() + "分</span>"; return dateDiff; }
/// <summary> /// 时间差值 /// </summary> /// <param name="dateTime1">比较时间1</param> /// <param name="dateTime2">比较时间2</param> /// <returns>返回相差天数、小时、分钟、秒</returns> public static string DateDiffToString(DateTime dateTime1, DateTime dateTime2) { string dateDiff = null; TimeSpan ts1 = new TimeSpan(dateTime1.Ticks); TimeSpan ts2 = new TimeSpan(dateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒"; return dateDiff; }
private int DateDiff(DateTime DateTime1, DateTime DateTime2) { int dateDiff = 0; TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); dateDiff = int.Parse(ts.Days.ToString()); return dateDiff; }
// Update is called once per frame void Update() { nowTime = System.DateTime.Now; System.TimeSpan ts1 = new System.TimeSpan(oldTime.Ticks); System.TimeSpan ts2 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts = ts2.Subtract(ts1).Duration(); if (ts.Seconds > 8 && !Input.anyKey) { flag_Roable = true; oldTime = System.DateTime.Now; } if (Input.anyKey) { if (Input.touchCount > 1) { if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved) { Vector2 tempPosition1 = Input.GetTouch(0).position; Vector2 tempPosition2 = Input.GetTouch(1).position; if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2)) { // distance = (transform.position - target.position).magnitude; // distance -= 0.5f; float oldScale = transform.localScale.x; float newScale = oldScale * 1.025f; if (newScale < startSalse * 3f) { transform.localScale = new Vector3(newScale, newScale, newScale); } // if (distance > 3.0f) // { // } } else { //if (distance < 18.5f) //{ // distance += 0.5f; // } float oldScale = transform.localScale.x; float newScale = oldScale / 1.025f; if (newScale > startSalse * 0.5f) { transform.localScale = new Vector3(newScale, newScale, newScale); } } //备份上一次触摸点的位置,用于对比 oldPosition1 = tempPosition1; oldPosition2 = tempPosition2; } } } }
public void DetermineTime() // This method fands the timespan for the visit. { ParseNeededInformation(); System.TimeSpan lngRTimeDiff = lngRTimeOut.Subtract(lngRTimeIn); System.TimeSpan lngATimeDiff = lngATimeOut.Subtract(lngRTimeIn); //System.TimeSpan lngATimeDiff = lngATimeDiff.Subtract(lngATimeDiff); System.TimeSpan detStandardTime = lngATimeDiff.Subtract(lngRTimeDiff); }
public void BuscarEvento() { System.TimeSpan hora_atual = System.TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")); Double segundos_corrido = hora_atual.Subtract(hora).TotalSeconds; if (segundos_corrido >= objUnidade.Tempo) { hora = hora_atual; Mensagem(VerificarEvento()); } }
// Update is called once per frame void Update() { nowTime = System.DateTime.Now; System.TimeSpan ts1 = new System.TimeSpan(oldTime.Ticks); System.TimeSpan ts2 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts = ts2.Subtract(ts1).Duration(); if (ts.Seconds > 8 && !Input.anyKey) { // flag_Roable = true; 3 oldTime = System.DateTime.Now; } if (Input.anyKey) { if (Input.touchCount == 2) { if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved) { //x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; //y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; x = Input.GetAxis("Mouse X") * xSpeed; y = Input.GetAxis("Mouse Y") * ySpeed; transform.Rotate(Vector3.up * -x * Time.deltaTime, Space.World); transform.Rotate(Vector3.right * y * Time.deltaTime, Space.World); } } if (Input.touchCount > 1) { if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved) { Vector2 tempPosition1 = Input.GetTouch(0).position; Vector2 tempPosition2 = Input.GetTouch(1).position; if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2)) { float oldScale = transform.localScale.x; float newScale = oldScale * 1.025f; transform.localScale = new Vector3(newScale, newScale, newScale); } else { float oldScale = transform.localScale.x; float newScale = oldScale / 1.025f; transform.localScale = new Vector3(newScale, newScale, newScale); } //备份上一次触摸点的位置,用于对比 oldPosition1 = tempPosition1; oldPosition2 = tempPosition2; } } } }
private void timer_Tick(object sender, EventArgs e) { //label1.Text = timer.ToString(); //System.TimeSpan second = new System.TimeSpan(0, 0, 0, 1); //System.TimeSpan curr = tSpan - second; //label1.Text = curr.ToString(); //this.tSpan = curr; //this.tSpan = tSpan - new System.TimeSpan(0, 0, 1, 0); tSpan = tSpan.Subtract(TimeSpan.FromSeconds(1)); label1.Text = tSpan.ToString(@"hh\:mm\:ss"); //label1.Text = tSpan.Hours + " " + tSpan.Minutes + " " + tSpan.Seconds; // MessageBox.Show("1 second"); }
static int Subtract(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.TimeSpan obj = (System.TimeSpan)ToLua.CheckObject(L, 1, typeof(System.TimeSpan)); System.TimeSpan arg0 = (System.TimeSpan)ToLua.CheckObject(L, 2, typeof(System.TimeSpan)); System.TimeSpan o = obj.Subtract(arg0); ToLua.PushValue(L, o); ToLua.SetBack(L, 1, obj); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public double getPastTimeByType(int timeType) { System.DateTime nowTime = System.DateTime.Now; switch (timeType) { case 0: return(getTotalYear(nowTime, inputTime)); case 1: return(getTotalMonth(nowTime, inputTime)); } System.TimeSpan ts1 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts2 = new System.TimeSpan(inputTime.Ticks); System.TimeSpan tsSub = ts1.Subtract(ts2).Duration(); return(getTimeByTimeSpan(tsSub, timeType)); }
private void GetTime() { if (time.Hours <= 0 && time.Minutes <= 0 && time.Seconds <= 0) { CancelInvoke("GetTime"); lblInfo.text = StaticLoc.Loc.Get("buttons644"); SetFavorable(false); isStart = false; } else { time = time.Subtract(timeSpan); //lblInfo.text = time.Hours + ":" + time.Minutes + StaticLoc.Loc.Get("info988"); lblInfo.text = time.Hours + StaticLoc.Loc.Get("info988") + time.Minutes + StaticLoc.Loc.Get("messages045"); tttttt = time.ToString(); } }
public double getFutureTimeByType(int timeType) { System.DateTime nowTime = System.DateTime.Now; switch (timeType) { case 6: return(getTotalYear(inputTimeFuture, nowTime)); case 7: return(getTotalMonth(inputTimeFuture, nowTime)); } System.TimeSpan ts1 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts2 = new System.TimeSpan(inputTimeFuture.Ticks); System.TimeSpan tsSub = ts2.Subtract(ts1).Duration(); return(getTimeByTimeSpan(tsSub, timeType - 6)); }
void mouseRotateAndScale(Transform check) { nowTime = System.DateTime.Now; System.TimeSpan ts1 = new System.TimeSpan(oldTime.Ticks); System.TimeSpan ts2 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts = ts2.Subtract(ts1).Duration(); if (ts.Seconds > 5 && !Input.anyKey) { flag_Roable = true; oldTime = System.DateTime.Now; } if (flag_Roable)//自动旋转 { x -= Time.deltaTime * 30; var rotation = Quaternion.Euler(0, x, 0); transform.RotateAround(mainObj.transform.position, Vector3.up, 0.3f); } }
/// <summary> /// 验证留言间隔时间 /// </summary> /// <param name="moduleEntity"></param> public void VerityTime(MessagesEntity moduleEntity) { MessagesEntity model = service.IQueryable(m => m.SessionId == moduleEntity.SessionId).OrderByDescending(m => m.CreatorTime).FirstOrDefault(); if (model != null && !string.IsNullOrEmpty(model.Id) && model.CreatorTime != null) { int timtNum = ConfigHelp.configHelp.MESSAGETIME; DateTime NowTime = DateTime.Now; TimeSpan tNow = new System.TimeSpan(NowTime.Ticks); TimeSpan tCreateTime = new System.TimeSpan(Convert.ToDateTime(model.CreatorTime).Ticks); TimeSpan tsSub = tNow.Subtract(tCreateTime).Duration(); if (tsSub.TotalSeconds < timtNum) { throw new Exception("请稍等一会再提交!"); } } }
void LogInterval(object sender, EventArgs e) { System.TimeSpan diff1 = DateTime.Now.Subtract(startTime); System.TimeSpan diff2 = diff1.Subtract(mAccumulatedVoidTime); App.Current.Dispatcher.Invoke((System.Action) delegate() { Log log = new Log(); log.Time = diff2.ToString(@"hh\:mm\:ss\:fff", System.Globalization.CultureInfo.InvariantCulture); log.mVideoTime = DateTime.Today.Add(mVideoPlayer.GetVideoPosition()).ToString("HH:mm:ss:fff"); log.mVideoTimeShort = DateTime.Today.Add(mVideoPlayer.GetVideoPosition()).ToString("HH:mm:ss"); log.LogValue = Math.Round(mJoystickAnnotate.GetValue() / 1000, 2); log.mLogIndex = debugIndex % 5; log.mDebugIndex = debugIndex; mLogging.Add(log); debugIndex++; }); }
public static string GetDateID(System.DateTime DateTime) { System.TimeSpan timeSpan = new System.TimeSpan(DateTime.Ticks); System.TimeSpan ts = new System.TimeSpan(System.Convert.ToDateTime("1900-01-01").Ticks); return(timeSpan.Subtract(ts).Duration().Days.ToString()); }
/// <summary> /// Subtracts two TimeSpans. /// </summary> /// <param name="timeSpan1">A TimeSpan.</param> /// <param name="timeSpan2">A TimeSpan.</param> /// <returns name="timeSpan">TimeSpan</returns> public static System.TimeSpan Subtract(System.TimeSpan timeSpan1, System.TimeSpan timeSpan2) { return(timeSpan1.Subtract(timeSpan2)); }
private static IEnumerable <string> TimeSpanToString(TimeSpan ts) { var readable = new List <string>(); if (ts == TimeSpan.MaxValue || ts == TimeSpan.MinValue || ts == TimeSpan.Zero) { return(readable); } // get absolute timespan ts = ts.Duration(); const int MaxItems = 3; if (ts.TotalDays > DaysInYear) { var whole = Convert.ToInt32(Math.Floor(ts.TotalDays / DaysInYear)); ts = ts.Subtract(new TimeSpan(whole * DaysInYear, 0, 0, 0)); readable.Add(whole + " year" + Plural(whole)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.TotalDays > DaysInMonth) { var whole = Convert.ToInt32(Math.Floor(ts.TotalDays / DaysInMonth)); ts = ts.Subtract(new TimeSpan(whole * DaysInMonth, 0, 0, 0)); readable.Add(whole + " month" + Plural(whole)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.TotalDays > DaysInWeek) { var whole = Convert.ToInt32(Math.Floor(ts.TotalDays / DaysInWeek)); ts = ts.Subtract(new TimeSpan(whole * DaysInWeek, 0, 0, 0)); readable.Add(whole + " week" + Plural(whole)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.Days > 0) { readable.Add(ts.Days + " day" + Plural(ts.Days)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.Hours > 0) { readable.Add(ts.Hours + " hour" + Plural(ts.Hours)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.Minutes > 0) { readable.Add(ts.Minutes + " minute" + Plural(ts.Minutes)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.Seconds > 0) { readable.Add(ts.Seconds + " second" + Plural(ts.Seconds)); if (readable.Count >= MaxItems) { return(readable); } } if (ts.Milliseconds > 0) { readable.Add(ts.Milliseconds + " ms"); if (readable.Count >= MaxItems) { return(readable); } } return(readable); }
public static string GetDateDiff(string Title, DateTime BeginDate, DateTime EndDate) { System.TimeSpan ts = new System.TimeSpan(BeginDate.Ticks); System.TimeSpan timeSpan = new System.TimeSpan(EndDate.Ticks); return(Title + "耗时:" + timeSpan.Subtract(ts).Duration().TotalSeconds.ToString() + "秒"); }
/// <summary> /// Gets the natural text for this timespan. For example "2 days, 4 hours and 3 minutes". /// </summary> public static string ToNaturalTime(this TimeSpan period, int precisionParts, bool longForm) { // TODO: Support months and years. // Hint: Assume the timespan shows a time in the past of NOW. Count years and months from there. // i.e. count years and go back. Then count months and go back... var names = new Dictionary <string, string> { { "year", "y" }, { "month", "M" }, { "week", "w" }, { "day", "d" }, { "hour", "h" }, { "minute", "m" }, { "second", "s" }, { " and ", " " }, { ", ", " " } }; Func <string, string> name = (k) => (longForm) ? k : names[k]; var parts = new Dictionary <string, double>(); if (period.TotalDays >= 365) { var years = (int)Math.Floor(period.TotalDays / 365); parts.Add(name("year"), years); period -= TimeSpan.FromDays(365 * years); } if (period.TotalDays >= 30) { var months = (int)Math.Floor(period.TotalDays / 30); parts.Add(name("month"), months); period -= TimeSpan.FromDays(30 * months); } if (period.TotalDays >= 7) { var weeks = (int)Math.Floor(period.TotalDays / 7); parts.Add(name("week"), weeks); period -= TimeSpan.FromDays(7 * weeks); } if (period.TotalDays >= 1) { parts.Add(name("day"), period.Days); period -= TimeSpan.FromDays(period.Days); } if (period.TotalHours >= 1 && period.Hours > 0) { parts.Add(name("hour"), period.Hours); period = period.Subtract(TimeSpan.FromHours(period.Hours)); } if (period.TotalMinutes >= 1 && period.Minutes > 0) { parts.Add(name("minute"), period.Minutes); period = period.Subtract(TimeSpan.FromMinutes(period.Minutes)); } if (period.TotalSeconds >= 1 && period.Seconds > 0) { parts.Add(name("second"), period.Seconds); period = period.Subtract(TimeSpan.FromSeconds(period.Seconds)); } else if (period.TotalSeconds > 0) { parts.Add(name("second"), period.TotalSeconds.Round(3)); period = TimeSpan.Zero; } var outputParts = parts.Take(precisionParts); var r = new StringBuilder(); foreach (var part in outputParts) { r.Append(part.Value); if (longForm) { r.Append(" "); } r.Append(part.Key); if (part.Value > 1 && longForm) { r.Append("s"); } if (outputParts.IndexOf(part) == outputParts.Count() - 2) { r.Append(name(" and ")); } else if (outputParts.IndexOf(part) < outputParts.Count() - 2) { r.Append(name(", ")); } } return(r.ToString()); }
void ClockTick() { timeLeft = timeLeft.Subtract(System.TimeSpan.FromSeconds(1)); }
// Update is called once per frame void Update() { AudioSource audio_src = this.GetComponent <AudioSource>(); if (audio_src == null) { return; } float beatLen = bellClip.length; float introLen = introClip.length; int minNext = System.DateTime.Now.TimeOfDay.Minutes, hrNext = System.DateTime.Now.TimeOfDay.Hours, hours = 0; int curHour = hrNext; if (minNext % 5 == 0) { minNext++; } while (minNext % 5 != 0) { minNext++; } minNext = 60;//every hour only if (minNext >= 60) { minNext = 0; hrNext++; } System.TimeSpan nextHour = new System.TimeSpan(hrNext, minNext, 0); System.TimeSpan lastTime = nextHour.Subtract(System.DateTime.Now.TimeOfDay); hours = nextHour.Hours; hours = hours > 12 ? hours - 12 : hours; if (hours == 0) { hours = 12; } float secsBeat = (beatLen) * hours + 1f; float secsIntro = introLen + 1f; if (Time.frameCount % 30 == 0 && false) { Debug.Log(string.Format("lastTime={0}, isIntro ={1}, secsIntro={2}, hours={3}, secsBeat={4}", lastTime.TotalSeconds, isIntro, secsIntro, hours, secsBeat)); } if (lastTime.TotalSeconds <= secsIntro && isIntro) { audio_src.Play(); isIntro = false; beatsLast = hours; if (beatsLast == 0) { beatsLast = 12; } } else if (!isIntro) { if (lastTime.TotalSeconds > secsIntro) { audio_src.clip = bellClip; } if (!audio_src.isPlaying && audio_src.clip == bellClip && beatsLast > 0) { audio_src.Play(); beatsPlayTime = Time.time; beatsLast--; } else if (audio_src.isPlaying && beatsPlayTime > 0 && Time.time - beatsPlayTime >= beatsCutPlayback && beatsLast > 0) { audio_src.Stop(); } else if (beatsLast == 0 && !audio_src.isPlaying) { isIntro = true; beatsPlayTime = 0; } } else if (audio_src.clip != introClip) { audio_src.clip = introClip; } }