The Code is as follows:
Copy codeThe Code is as follows:
String start = Request. Form. Get ("date2"). ToString (); // Get the start date. This control is an html control.
String end = Request. Form. Get ("date3"). ToString (); // obtain the end date. This control is an html control.
String [] start_date = start. Split ('-'); // separates the year, month, and day of the start date.
String [] end_date = end. Split ('-'); // separates the year, month, and day of the end date.
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;
// Define the global variable public string table_td = ""; then assign a value
Table_td = "<table> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </tr> ";
// Determine the start time as the day of the week. For example, if it is Wednesday, two cells need to be left blank before, and so on.
Switch (dt1.DayOfWeek. ToString ())
{
Case "Tuesday ":
Table_td + = "<tr> <td> </td> ";
Break;
Case "Wednesday ":
Table_td + = "<tr> <td> </td> ";
Break;
Case "Thursday ":
Table_td + = "<tr> <td> </td> ";
Break;
Case "Friday ":
Table_td + = "<tr> <td> </td> ";
Break;
Case "Saturday ":
Table_td + = "<tr> <td> </ td> ";
Break;
Case "Sunday ":
Table_td + = "<tr> <td> </ td> </td> ";
Break;
}
// Recursion to End Time
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;
}
}
// End
Table_td + = "</tr> </table> ";
Print table_td.
The above is my own, but I don't think so. Below I will provide the code that someone else will give me after I finish it. The Code is as follows:
Copy codeThe Code is as follows:
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;
}
Copy codeThe Code is as follows:
StringBuilder sb = new StringBuilder ();
Sb. Remove (0, sb. Length );
Sb. append ("<table> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </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 ());
After reading this, the idea is basically the same, but it is impossible for beginners. Continue to work.