实现效果:
知识运用:
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(); }
原文地址:https://www.cnblogs.com/feiyucha/p/10188113.html
时间: 2024-10-21 07:28:26