计算两个日期之间的工作日天数(哪里出错了?)
程序代码:
namespace p118_3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DateTime dt1 = Convert.ToDateTime(textBox1.Text); DateTime dt2 = Convert.ToDateTime(textBox2.Text); TimeSpan ts1 = dt2.Subtract(dt1); int countday = ts1.Days; int weekday = 0; for (int i = 0; i < countday; i++) ; DateTime tempdt = dt1.Date.AddDays(1); if (tempdt.DayOfWeek != System.DayOfWeek.Saturday && tempdt.DayOfWeek != System.DayOfWeek.Sunday) { weekday++; } label4 .Text = string .Format ("{0:D}到{0:D}之间的工作日共有{1}天",dt1 ,dt2 ,weekday ); } } }