如何将TimeSpan转换为INT类型?
做一个程序,需要以某一天为起点,计算单双周,我的思路是以时间差对7求模的方式根据摸的数值来确定周数以及单双周. 但是最后对TimeSpan进行计算的时候系统提示说TimeSpan无法转换为INT类型. 代码如下:
public class WeekPro
{
DateTime StartDate = new DateTime(2010, 02, 22);
public String DetectWeek()
{
String WeekDetect;
TimeSpan DayDf = DateTime.Today - StartDate;
int DayDfInt = Convert.ToInt32(DayDf);
if (DayDfInt % 7 != 0)
{
DayDfInt = DayDfInt / 7 + 1;
}
else
{
DayDfInt = DayDfInt / 7;
}
if (DayDfInt / 2 == 0)
{
WeekDetect = "Double";
}
else
{
WeekDetect = "Single";
}
return WeekDetect;
}
public string DetectWeek(int Days)
{
String WeekDetect;
TimeSpan DayDf = DateTime.Now.AddDays(Days) - StartDate;
int DayDfInt = Convert.ToInt32(DayDf);
if (DayDfInt % 7 != 0)
{
DayDfInt = DayDfInt / 7 + 1;
}
else
{
DayDfInt = DayDfInt / 7;
}
if (DayDfInt / 2 == 0)
{
WeekDetect = "Double";
}
else
{
WeekDetect = "Single";
}
return WeekDetect;
}
public string DetectWeek(DateTime AssDays)
{
String WeekDetect;
TimeSpan DayDf = AssDays - StartDate;
int DayDfInt = Convert.ToInt32(DayDf);
if (DayDfInt % 7 != 0)
{
DayDfInt = DayDfInt / 7 + 1;
}
else
{
DayDfInt = DayDfInt / 7;
}
if (DayDfInt / 2 == 0)
{
WeekDetect = "Double";
}
else
{
WeekDetect = "Single";
}
return WeekDetect;
}
}