⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dateutil.cs

📁 内容管理 内容管理 内容管理 内容管理 内容管理
💻 CS
字号:
using System;

namespace eInfo.common
{
	/// <summary>
	/// 日期处理函数包
	/// </summary>
	public class DateUtil
	{
		//构造函数
		public DateUtil()
		{

		}
		

    #region 方法


        //验证日期的合法性
		public static bool ValidDate(string strYear, string strMonth ,string strDay)
		{
			try
			{
				//未输入日期
				if((strYear=="")&&(strMonth=="")&&(strDay==""))
				{
					return true;
				}

				//输入日期
				int year=System.Convert.ToInt16(strYear);
				int month=System.Convert.ToInt16(strMonth);
				int day=System.Convert.ToInt16(strDay);
				DateTime date = new DateTime(year,month,day);
				int numday = DateTime.DaysInMonth(year,month);
				if (day>numday)return false;
				return true;

			}
			catch
			{
				return false;
			}
		}

		/// <summary>
		/// 判断是否为合法日期,必须大于1800年1月1日
		/// </summary>
		/// <param name="strDate">输入日期字符串</param>
		/// <returns>True/False</returns>
		public static bool IsDateTime(string strDate)
		{
			try
			{
				DateTime oDate=DateTime.Parse(strDate); 
				if(oDate.CompareTo(DateTime.Parse("1800-1-1") )>0)
					return true;
				else
					return false;
			}
			catch(Exception)
			{
				return false;
			}
		}

		#endregion


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -