You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB
C#

10 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace DSWebMobile.Handler
{
/// <summary>
/// DayOfMonth 的摘要说明
/// </summary>
public class DayOfMonth : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string action = context.Request.QueryString["action"].ToString();
switch (action)
{
case "0":
GetFirstDayOfMonth(context);
break;
case "1":
GetLastDayOfMonth(context);
break;
}
}
private void GetFirstDayOfMonth(HttpContext context)//int Year, int Month
{
string date = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-01";
StringBuilder sb = new StringBuilder();
sb.AppendLine("[{\"date\":\"" + date + "\"}]");
context.Response.ContentType = "text/plain";
context.Response.Write(sb.ToString());
context.Response.End();
}
private void GetLastDayOfMonth(HttpContext context)
{
//这里的关键就是 DateTime.DaysInMonth 获得一个月中的天数
int Year=int.Parse(DateTime.Today.Year.ToString());
int Month=int.Parse(DateTime.Today.Month.ToString());
int Days = DateTime.DaysInMonth(Year, Month);
string date = DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-" + Days.ToString();
StringBuilder sb = new StringBuilder();
sb.AppendLine("[{\"date\":\"" + date + "\"}]");
context.Response.ContentType = "text/plain";
context.Response.Write(sb.ToString());
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}