方法一:
protected void Page_Load(object sender, EventArgs e)
{
string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string[] data = { "2015-03-15", "2015-03-16", "2015-03-17", "2015-03-18", "2015-03-19", "2015-03-20", "2015-03-21" };
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
int y = Convert.ToInt32(Convert.ToDateTime(data[i]).DayOfWeek.ToString("d"));
Response.Write(y);
Response.Write("</br>");
//string week = Day[y].ToString();
DateTime start = (Convert.ToDateTime(data[i])).AddDays(1 - y);
DateTime end = (Convert.ToDateTime(data[i])).AddDays(6 - y);
sb.Append("</br>");
sb.Append(":" + data[i] + " 本周开始:" + start + " 本周结束" + end + " \n");
sb.Append("</br>");
}
Response.Write(sb.ToString());
}
方法二:
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
string[] data = getNowTime((DateTime.Now.DayOfWeek.ToString("d"))).Split(',');
int num = Shove._Convert.StrToInt(DateTime.Now.DayOfWeek.ToString("d"), 0);
List<string> wheres = new List<string>();
for (int i = 0; i < Shove._Convert.StrToInt(data[0].ToString(), 0); i++)//前面
{
wheres.Add(DateTime.Now.AddDays(i - num).ToString("yyyy-MM-dd"));
}
//今天
wheres.Add(DateTime.Now.ToString("yyyy-MM-dd"));
//今天以后的
for (int i = 0; i < Shove._Convert.StrToInt(data[1].ToString(), 0); i++)
{
wheres.Add(DateTime.Now.AddDays(i + 1).ToString("yyyy-MM-dd"));
}
for (int i = 0; i < wheres.Count; i++)
{
//wheres[i].ToString() + " 59:59:59";
}
}
public string getNowTime(string str)
{
string strTemp = "";
switch (str)
{
case "0":
strTemp = "0,6";
break;
case "1":
strTemp = "1,5";
break;
case "2":
strTemp = "2,4";
break;
case "3":
strTemp = "3,3";
break;
case "4":
strTemp = "4,2";
break;
case "5":
strTemp = "5,1";
break;
case "6":
strTemp = "6,0";
break;
default:
strTemp = "0,6";
break;
}
return strTemp;
}