thisMonth() //返回月初
thisMonthEnd() //返回月末
thisSeason() //返回季度初
thisSeasonEnd() //返回季度末
thisYear() //返回年初
thisYearEnd() //返回年末
public String thisMonth(DateTime date)
{
String strY = null;
int x, y;
x = Convert.ToInt32(date.Year.ToString());
y = Convert.ToInt32(date.Month.ToString());
strY = y >= 10 ? y.ToString() : ("0" + y); return x + "年" + strY + "月01日";
}
public String thisMonthEnd(DateTime date)
{
int x, y;
String strY = null;
String strZ = null;
bool leap = false;
x = Convert.ToInt32(date.Year.ToString());
y = Convert.ToInt32(date.Month.ToString());
if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
{
strZ = "31";
}
if (y == 4 || y == 6 || y == 9 || y == 11)
{
strZ = "30";
}
if (y == 2)
{
leap = leapYear(x);
if (leap)
{
strZ = "29";
}
else
{
strZ = "28";
}
}
strY = y >= 10 ? y.ToString() : ("0" + y);
return x + "年" + strY + "月" + strZ + "日";
}
public String thisSeason(DateTime date)
{
String dateString = "";
int x, y;
x = Convert.ToInt32(date.Year.ToString());
y = Convert.ToInt32(date.Month.ToString());
if (y >= 1 && y <= 3)
{
dateString = x + "-" + "01" + "-" + "01";
}
if (y >= 4 && y <= 6)
{
dateString = x + "-" + "04" + "-" + "01";
}
if (y >= 7 && y <= 9)
{
dateString = x + "-" + "07" + "-" + "01";
}
if (y >= 10 && y <= 12)
{
dateString = x + "-" + "10" + "-" + "01";
}
return dateString;
}
public String thisSeasonEnd(DateTime date)
{
String dateString = "";
int x, y;
x = Convert.ToInt32(date.Year.ToString());
y = Convert.ToInt32(date.Month.ToString());
if (y >= 1 && y <= 3)
{
dateString = x + "-" + "03" + "-" + "31";
}
if (y >= 4 && y <= 6)
{
dateString = x + "-" + "06" + "-" + "30";
}
if (y >= 7 && y <= 9)
{
dateString = x + "-" + "09" + "-" + "30";
}
if (y >= 10 && y <= 12)
{
dateString = x + "-" + "12" + "-" + "31";
}
return dateString;
}
public String thisYear(DateTime date)
{
int x;
x = Convert.ToInt32(date.Year.ToString());
return x + "-01" + "-01";
}
public String thisYearEnd(DateTime date)
{
int x;
x = Convert.ToInt32(date.Year.ToString());
return x + "-12" + "-31";
}
public bool leapYear(int year)
{
bool leap;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0) leap = true;
else leap = false;
}
else leap = true;
}
else leap = false;
return leap;
}