如果星期天是一周的第一天:
private void button1_Click(object sender, System.EventArgs e)
{
DateTime dt = DateTime.Now.AddDays(- (int)DateTime.Now.DayOfWeek);
for(int i = 0; i < 7; i++)
{
this.textBox1.Text += "\r\n" + dt.AddDays(i).ToString("yyyy-MM-dd");
}
}
如果星期天是一周的最后一天:
private void button2_Click(object sender, System.EventArgs e)
{
DateTime dt;
if(DateTime.Now.DayOfWeek == 0)
{
dt = DateTime.Now.AddDays( - 6);
}
else
{
dt = DateTime.Now.AddDays(1 - (int)DateTime.Now.DayOfWeek);
}
for(int i = 0; i < 7; i++)
{
this.textBox1.Text += "\r\n" + dt.AddDays(i).ToString("yyyy-MM-dd");
}
}
我在做人才网的时候,要求列出本周星期一到星期七的日期,用到此方法.
Snowdust(雪尘)
回复于 2006-01-13 09:35:34 得分 30
转载于:https://www.cnblogs.com/luyongqun/archive/2007/12/03/981152.html