计时器格式正确 [英] timer in proper format

查看:106
本文介绍了计时器格式正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

m使用测试模块的计时器并面对问题我的计时器只显示秒数没有剩余的分钟秒数plz帮助我解决这个问题我的代码是这样的计时器



  protected   void  Timer1_Tick( object  sender,EventArgs e)
{
if (Session [ timeout]!= null
{
if 0 > DateTime.Compare(DateTime.Now,DateTime.Parse(Session [ timeout]。ToString( ))))
{
Label6.Text = 秒数: +(( Int32 )DateTime.Parse(会话[ 超时]的ToString())中减去(DateTime.Now).TotalSeconds)的ToString()。;
}
其他
{
.Button5_Click (发件人,e);
}
}
}

解决方案



< pre lang =c#> DateTime TimeLimit = DateTime.Parse(Session [ timeout]。ToString ());
DateTime ElapsedTime = DateTime.Now;
TimeSpan CountDownTime = TimeLimit.Subtract(ElapsedTime);

Label6.Text = CountDownTime.Minutes.ToString( 00) + + CountDownTime.Seconds.ToString( 00);



快乐编码!

:)


m Using the timer for the exam module and facing the problem my timer is showing just the seconds no with the remaining minutes with seconds plz help me to solve this my code is like this for timer

protected void Timer1_Tick(object sender, EventArgs e)
   {
       if (Session["timeout"] != null)
       {
           if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
           {
               Label6.Text = "seconds left : " + ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalSeconds).ToString();
           }
           else
           {
               this.Button5_Click(sender, e);
           }
       }
   }

解决方案

Hi,

DateTime TimeLimit = DateTime.Parse(Session["timeout"].ToString());
DateTime ElapsedTime = DateTime.Now;
TimeSpan CountDownTime = TimeLimit.Subtract(ElapsedTime);

Label6.Text = CountDownTime.Minutes.ToString("00") + ":" + CountDownTime.Seconds.ToString("00");


Happy Coding!
:)


这篇关于计时器格式正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆