[时间操作] C#DateFormat时间帮助类 (转载)

点击下载 DateFormat.rar

主要功能如下

返回每月的第一天和最后一天

看下面代码吧

/// <summary>
/// 类说明:时间操作类
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System; namespace DotNet.Utilities
{
public class DateFormat
{
//返回每月的第一天和最后一天
public static void ReturnDateFormat(int month, out string firstDay, out string lastDay)
{
int year = DateTime.Now.Year + month / ;
if (month != )
{
month = month % ;
}
switch (month)
{
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
if (DateTime.IsLeapYear(DateTime.Now.Year))
lastDay = DateTime.Now.ToString(year + "-0" + month + "-29");
else
lastDay = DateTime.Now.ToString(year + "-0" + month + "-28");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString("yyyy-0" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-30");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-30");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-0" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-0" + month + "-30");
break;
case :
firstDay = DateTime.Now.ToString(year + "-" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-" + month + "-31");
break;
case :
firstDay = DateTime.Now.ToString(year + "-" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-" + month + "-30");
break;
default:
firstDay = DateTime.Now.ToString(year + "-" + month + "-01");
lastDay = DateTime.Now.ToString(year + "-" + month + "-31");
break;
}
}
}
}
上一篇:【Java解惑】表达式问题


下一篇:C++中explicit的用法