qq_35509878 于 2016.09.12 17:21 提问

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds= new ItemQueryDataDP().GetITEMCODEByid("12");
string q=ds.Tables[0].Rows[0][0].ToString();
DateTime datet = Convert.ToDateTime("2016/9/30 12:23:23");
DateTime datet2 = Convert.ToDateTime("2016/10/30 12:23:23");
TimeSpan span = datet2.Subtract(datet);
int dayDiff = span.Days + 1;
int totleWeek = dayDiff / 7;
int yuDay = dayDiff % 7;
int lastDay = 0;
if (yuDay == 0) //正好整个周
{
lastDay = dayDiff - (totleWeek * 2);
}
else
{
int weekDay = 0;
int endWeekDay = 0; //多余的天数有几天是周六或者周日
switch (datet.DayOfWeek)
{
case DayOfWeek.Monday:
weekDay = 1;
break;
case DayOfWeek.Tuesday:
weekDay = 2;
break;
case DayOfWeek.Wednesday:
weekDay = 3;
break;
case DayOfWeek.Thursday:
weekDay = 4;
break;
case DayOfWeek.Friday:
weekDay = 5;
break;
case DayOfWeek.Saturday:
weekDay = 6;
break;
case DayOfWeek.Sunday:
weekDay = 7;
break;
}
if ((weekDay == 6 && yuDay >= 2) || (weekDay == 7 && yuDay >= 1) || (weekDay == 5 && yuDay >= 3) || (weekDay == 4 && yuDay >= 4) || (weekDay == 3 && yuDay >= 5) || (weekDay == 2 && yuDay >= 6) || (weekDay == 1 && yuDay >= 7))
{
endWeekDay = 2;
}
if ((weekDay == 6 && yuDay < 1) || (weekDay == 7 && yuDay < 5) || (weekDay == 5 && yuDay < 2) || (weekDay == 4 && yuDay < 3) || (weekDay == 3 && yuDay < 4) || (weekDay == 2 && yuDay < 5) || (weekDay == 1 && yuDay < 6))
{
endWeekDay = 1;
}
lastDay = dayDiff - (totleWeek * 2) - endWeekDay;
}
lblTime.Text = lastDay.ToString();
}

2个回答

simonezhlx   2016.09.13 09:52

qq_35509878   2016.09.13 10:03