日期:2014-05-19  浏览次数:20511 次

初学者问个简单的问题``asp.net中如何获得上个星期日的日期啊`
asp.net中如何获得上个星期日的日期啊`比如我要获得上个星期日的日期:2007-5-7
在线等``刚到贵站`...谢谢``

------解决方案--------------------
DateTime now = DateTime.Now;
DayOfWeek week = now.DayOfWeek;
switch (week)
{
case System.DayOfWeek.Friday:
Label2.Text = DateTime.Now.AddDays(-5).ToString();
break;
case System.DayOfWeek.Monday:
Label2.Text = DateTime.Now.AddDays(-1).ToString();
break;
case System.DayOfWeek.Saturday:
Label2.Text = DateTime.Now.AddDays(-6).ToString();
break;
case System.DayOfWeek.Sunday:
Label2.Text = DateTime.Now.AddDays(-7).ToString();
break;
case System.DayOfWeek.Thursday:
Label2.Text = DateTime.Now.AddDays(-4).ToString();
break;
case System.DayOfWeek.Tuesday:
Label2.Text = DateTime.Now.AddDays(-2).ToString();
break;
case System.DayOfWeek.Wednesday:
Label2.Text = DateTime.Now.AddDays(-3).ToString();
break;

}
------解决方案--------------------
DateTime d;
if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
d=DateTime.Now.AddDays(-7);
else
d=DateTime.Now.AddDays(-1*Convert.ToDouble(DateTime.Now.DayOfWeek));
return d.ToLongDateString() ;