码迷,mamicode.com
首页 > 其他好文 > 详细

使用Timer组件实现倒计时

时间:2018-12-27 23:43:28      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:.com   diff   代码   sha   textbox   运用   图片   src   sharp   

实现效果:

  技术分享图片

知识运用:

   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组件实现倒计时

标签:.com   diff   代码   sha   textbox   运用   图片   src   sharp   

原文地址:https://www.cnblogs.com/feiyucha/p/10188113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!