使用Timer组件实现倒计时

Posted feiyucha

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Timer组件实现倒计时相关的知识,希望对你有一定的参考价值。

实现效果:

  技术分享图片

知识运用:

   Timer组件的Enabed属性

实现代码:

        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime get_time = DateTime.Now;
            DateTime str_time = DateTime.Parse(dateTimePicker1.Text.Substring(0,19));
            textBox1.Text = get_time.ToString();
            txtyear.Text = DateAndTime.DateDiff(
                "yyyy",get_time,str_time,FirstDayOfWeek.Sunday,FirstWeekOfYear.FirstFourDays).ToString();
            txtmonth.Text = DateAndTime.DateDiff(
                "m", get_time, str_time, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
            txtday.Text = DateAndTime.DateDiff(
                "d", get_time, str_time, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
            txthour.Text = DateAndTime.DateDiff(
                "h", get_time, str_time, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
            txtmintue.Text = DateAndTime.DateDiff(
                "m", get_time, str_time, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
            txtsecon.Text = DateAndTime.DateDiff(
                "s", get_time, str_time, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays).ToString();
        }

 

以上是关于使用Timer组件实现倒计时的主要内容,如果未能解决你的问题,请参考以下文章

Java Swing的计时器组件Timer

vb中timer怎么用

求 JAVA 使用 Thread 和 Timer 类来做倒计时的程序代码

Flutter ValueNotifier 倒计时 局部刷新组件 在StatelessWidget 中刷新倒计时

React中发送验证码 倒计时效果组件编写

boost中使用 timer