代码如下:
复制代码 代码如下:
string start = Request.Form.Get("date2").ToString(); //获取开始日期,此控件为html控件
string end = Request.Form.Get("date3").ToString(); //获取结束日期,此控件为html控件
string[] start_date = start.Split('-'); //分离出开始日期的年、月、日
string[] end_date = end.Split('-'); //分离出结束日期的年、月、日
DateTime dt1 = new DateTime(int.Parse(start_date[0]), int.Parse(start_date[1]), int.Parse(start_date[2]));
DateTime dt2 = new DateTime(int.Parse(end_date[0]), int.Parse(end_date[1]), int.Parse(end_date[2]));
TimeSpan ts = dt2 - dt1;
//定义全局变量public string table_td = "";然后进行赋值
table_td = "<table><tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期天</td></tr>";
//判断开始时间为星期几,如,如果是星期三,则需要前面空出2个单元格出来,以此类推
switch (dt1.DayOfWeek.ToString())
{
case "Tuesday":
table_td += "<tr><td></td>";
break;
case "Wednesday":
table_td += "<tr><td></td><td></td>";
break;
case "Thursday":
table_td += "<tr><td></td><td></td><td></td>";
break;
case "Friday":
table_td += "<tr><td></td><td></td><td></td><td></td>";
break;
case "Saturday":
table_td += "<tr><td></td><td></td><td></td><td></td><td></td>";
break;
case "Sunday":
table_td += "<tr><td></td><td></td><td></td><td></td><td></td><td></td>";
break;
}
//递归至结束时间
for (int i = 0; i < ts.Days; i++)
{
string sdate = dt1.AddDays(i).Day.ToString();
switch (dt1.AddDays(i).DayOfWeek.ToString())
{
case "Monday":
table_td += "<tr><td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Tuesday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Wednesday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Thursday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Friday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Saturday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Sunday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td></tr>";
break;
}
}
//结束
table_td += "</tr></table>";
打印table_td即可。
以上是我自己写的,但觉得不怎么样,下面我提供下别人在我做完后,做给我的,代码如下:
复制代码 代码如下:
int weekIndex(string item)
{
string[] week = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
int index = -1;
for (int i = 0; i < week.Length; i++)
{
if (week[i].Trim().ToUpper() == item.ToUpper().Trim())
{
index = i;
break;
}
}
return index;
}
复制代码 代码如下:
StringBuilder sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("<table><tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期天</td></tr>");
DateTime dt1 = new DateTime(2010, 3, 16);
DateTime dt2 = new DateTime(2010, 4, 13);
TimeSpan ts = dt2 - dt1;
int index; DateTime dtTemp;
for (int i = 0; i < ts.Days; i++) {
dtTemp=dt1.AddDays(i);
index = weekIndex(dtTemp.DayOfWeek.ToString());
if (index == 0 && i > 0)
{
sb.AppendFormat("<tr><td>{0}</td>", dtTemp.ToString("MM-dd"));
}
else if (index > 0 && i == 0)
{
sb.Append("<tr>");
for (int j = 0; j <= index - 1; j++)
{
sb.Append("<td> </td>");
}
sb.AppendFormat("<td>{0}</td>", dtTemp.ToString("MM-dd"));
}
else if (index == 6 && i>0)
{
sb.AppendFormat("<td>{0}</td></tr>", dtTemp.ToString("MM-dd"));
}
else {
sb.AppendFormat("<td>{0}</td>", dtTemp.ToString("MM-dd"));
}
}
sb.Append("</table>");
Response.Write(sb.ToString());
看完后,大致上的想法是一样的,只是.......初学者没办法。继续努力。
复制代码 代码如下:
string start = Request.Form.Get("date2").ToString(); //获取开始日期,此控件为html控件
string end = Request.Form.Get("date3").ToString(); //获取结束日期,此控件为html控件
string[] start_date = start.Split('-'); //分离出开始日期的年、月、日
string[] end_date = end.Split('-'); //分离出结束日期的年、月、日
DateTime dt1 = new DateTime(int.Parse(start_date[0]), int.Parse(start_date[1]), int.Parse(start_date[2]));
DateTime dt2 = new DateTime(int.Parse(end_date[0]), int.Parse(end_date[1]), int.Parse(end_date[2]));
TimeSpan ts = dt2 - dt1;
//定义全局变量public string table_td = "";然后进行赋值
table_td = "<table><tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期天</td></tr>";
//判断开始时间为星期几,如,如果是星期三,则需要前面空出2个单元格出来,以此类推
switch (dt1.DayOfWeek.ToString())
{
case "Tuesday":
table_td += "<tr><td></td>";
break;
case "Wednesday":
table_td += "<tr><td></td><td></td>";
break;
case "Thursday":
table_td += "<tr><td></td><td></td><td></td>";
break;
case "Friday":
table_td += "<tr><td></td><td></td><td></td><td></td>";
break;
case "Saturday":
table_td += "<tr><td></td><td></td><td></td><td></td><td></td>";
break;
case "Sunday":
table_td += "<tr><td></td><td></td><td></td><td></td><td></td><td></td>";
break;
}
//递归至结束时间
for (int i = 0; i < ts.Days; i++)
{
string sdate = dt1.AddDays(i).Day.ToString();
switch (dt1.AddDays(i).DayOfWeek.ToString())
{
case "Monday":
table_td += "<tr><td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Tuesday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Wednesday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Thursday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Friday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Saturday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td>";
break;
case "Sunday":
table_td += "<td><a onmouseover=selStation(1); onmouseout=chide();>" + sdate + "</a></td></tr>";
break;
}
}
//结束
table_td += "</tr></table>";
打印table_td即可。
以上是我自己写的,但觉得不怎么样,下面我提供下别人在我做完后,做给我的,代码如下:
复制代码 代码如下:
int weekIndex(string item)
{
string[] week = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
int index = -1;
for (int i = 0; i < week.Length; i++)
{
if (week[i].Trim().ToUpper() == item.ToUpper().Trim())
{
index = i;
break;
}
}
return index;
}
复制代码 代码如下:
StringBuilder sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("<table><tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期天</td></tr>");
DateTime dt1 = new DateTime(2010, 3, 16);
DateTime dt2 = new DateTime(2010, 4, 13);
TimeSpan ts = dt2 - dt1;
int index; DateTime dtTemp;
for (int i = 0; i < ts.Days; i++) {
dtTemp=dt1.AddDays(i);
index = weekIndex(dtTemp.DayOfWeek.ToString());
if (index == 0 && i > 0)
{
sb.AppendFormat("<tr><td>{0}</td>", dtTemp.ToString("MM-dd"));
}
else if (index > 0 && i == 0)
{
sb.Append("<tr>");
for (int j = 0; j <= index - 1; j++)
{
sb.Append("<td> </td>");
}
sb.AppendFormat("<td>{0}</td>", dtTemp.ToString("MM-dd"));
}
else if (index == 6 && i>0)
{
sb.AppendFormat("<td>{0}</td></tr>", dtTemp.ToString("MM-dd"));
}
else {
sb.AppendFormat("<td>{0}</td>", dtTemp.ToString("MM-dd"));
}
}
sb.Append("</table>");
Response.Write(sb.ToString());
看完后,大致上的想法是一样的,只是.......初学者没办法。继续努力。
标签:
asp.net,时间段,星期
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net 获取某个时间段的星期并以表格形式排列出来”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。