Timespan 事件对比问题

CuiQG丶 发布于 2014/04/13 11:00
阅读 71
收藏 0

 private void timeAuto()
        { 
                DateTime nowTime = DateTime.Now.ToLocalTime();
                DateTime firTime = Convert.ToDateTime(firH.Text + ":" + firM.Text + ":" + firS.Text);
                DateTime secTime = Convert.ToDateTime(secH.Text + ":" + secM.Text + ":" + secS.Text);
            

                TimeSpan tsTime = TimeSpan.Zero;
                string msg = string.Empty;
                if (nowTime.CompareTo(firTime) < 0)
                {
                    tsTime = firTime - nowTime;
                    msg = string.Format("据下次执行还有:{0}时{1}分{2}秒", tsTime.Hours, tsTime.Minutes, tsTime.Seconds);
                }
                else if (nowTime.CompareTo(firTime) > 0 && nowTime.CompareTo(secTime) < 0)
                {
                    tsTime = secTime - nowTime;
                    msg = string.Format("据下次执行还有:{0}时{1}分{2}秒", tsTime.Hours, tsTime.Minutes, tsTime.Seconds);
                }

                else if (nowTime.CompareTo(secTime) > 0)
                {
                    tsTime = firTime.AddDays(1) - nowTime;
                    msg = string.Format("据下次执行还有:{0}时{1}分{2}秒", tsTime.Hours, tsTime.Minutes, tsTime.Seconds);
                }

                else if (nowTime.CompareTo(firTime) == 0 || nowTime.CompareTo(secTime) == 0)
                {

                    lblTime.Text = "正在同步...";
                    Toledo toledo = new Toledo();
                    toledo.emptyFile();
                    lblManual.Text = toledo.getInfo();
                    toledo.tSync();
                    sendMail sm = new sendMail();
                    sm.sMail(toledo.getFile());
                    Thread.Sleep(3000);
                }
               
                lblTime.Text = tsTime.ToString()+"// \n"+nowTime.ToString() +"\n"+firTime.ToString()+"\n"+secTime.ToString();
                



//firH.Text,firM.Text,firS.Text,secH.Text,secM.Text,secS.Text 为string 类型 }nowTime.CompareTo(firTime) == 0 一直不执行,大神们只是为何啊!

加载中
返回顶部
顶部