根据当期时间得到本周第一天和最后一天
/// <summary>
/// 根据指定接收本周第一天和最后一天
/// </summary>
/// <param name="day">当前日期</param>
/// <param name="sDate">本周第一天</param>
/// <param name="eDate">本周最后一天</param>
public static void GetWeekStarAndEnd(DateTime day, out DateTime sDate, out DateTime eDate)
{
sDate = DateTime.MinValue;
eDate = DateTime.MinValue;
switch (day.DayOfWeek)
{
case DayOfWeek.Monday:
sDate = Convert.ToDateTime(day.ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Tuesday:
sDate = Convert.ToDateTime(day.AddDays(-1).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Wednesday:
sDate = Convert.ToDateTime(day.AddDays(-2).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Thursday:
sDate = Convert.ToDateTime(day.AddDays(-3).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Friday:
sDate = Convert.ToDateTime(day.AddDays(-4).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Saturday:
sDate = Convert.ToDateTime(day.AddDays(-5).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
case DayOfWeek.Sunday:
sDate = Convert.ToDateTime(day.AddDays(-6).ToString("yyyy-MM-dd"));
eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
break;
}
}
/// <summary>
/// 根据指定时间计算旬起始日期
/// </summary>
/// <param name="day">当前日期</param>
/// <param name="sDate">旬开始日期</param>
/// <param name="eDate">旬结束日期</param>
/// <returns>返回旬(上旬,中旬,下旬)</returns>
public static string Xun(DateTime day, out DateTime sDate, out DateTime eDate)
{
string ss = "";
sDate = DateTime.MinValue;
eDate = DateTime.MinValue;
if (day.Day > 0 && day.Day < 11)
{
sDate = new DateTime(day.Year, day.Month, 1);
eDate = new DateTime(day.Year, day.Month, 10, 23, 59, 59);
ss = "上旬";
}
if (day.Day > 10 && day.Day < 21)
{
sDate = new DateTime(day.Year, day.Month, 11);
eDate = new DateTime(day.Year, day.Month, 20, 23, 59, 59);
ss = "中旬";
}
if (day.Day > 20 && day.Day <= 31)
{
sDate = new DateTime(day.Year, day.Month, 21);
eDate = new DateTime(day.Year, day.Month, Convert.ToDateTime(day.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).Day, 23, 59, 59);
ss = "下旬";
}
return ss;
}
/// <summary>
/// 计算季度
/// </summary>
/// <param name="day">当前日期</param>
/// <param name="sDate">季度开始日期</param>
/// <param name="eDate">季度结束日期</param>
/// <returns>季度日期</returns>
public static string JiDu(DateTime day, out DateTime sDate, out DateTime eDate)
{
string ss = "";
sDate = DateTime.MinValue;
eDate = DateTime.MinValue;
if (day.Month > 0 && day.Month < 4)
{
sDate = new DateTime(day.Year, 1, 1);
ss = "第一季度";
}
if (day.Month > 3 && day.Month < 7)
{
sDate = new DateTime(day.Year, 4, 1);
ss = "第二季度";
}
if (day.Month > 7 && day.Month < 10)
{
sDate = new DateTime(day.Year, 7, 1);
ss = "第三季度";
}
if (day.Month > 10 && day.Month <= 12)
{
sDate = new DateTime(day.Year, 10, 1);
ss = "第四季度";
}
eDate = Convert.ToDateTime(sDate.AddMonths(3).ToString("yyyy-MM-01")).AddDays(-1);
return ss;
}