闰年的二月当然是29天,还要验证吗? 其实我知道你的意思: 你可以这样来:把你的如:2004/2/29 赋值给 DateTimePicker.MinDate or MaxDate 因为非闰年的二月没有29所以如果是2003年就会抛出异常;往下的你应该知道怎么做了。 大月小月可以使用相同的方法;只要检验有没有31不就成了。
我是想用在Web程序上的,不是应用在Win平台上的。
工具箱里RangeValidator。只要设置好属性就ok了
// DatePicker for .NET by Lutz Roeder, October 2000 // http://www.aisto.com/roeder/dotnet, // [email protected] 应该会有一些相关信息
我察看了帮助,发现这个你可以看看:DateTime.DaysInMonth 方法 [C#]请参见 DateTime 结构 | DateTime 成员 | System 命名空间 | DateTime 成员(Visual J# 语法) | C++ 托管扩展编程 要求 平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准 语言 C#C++JScriptVisual Basic全部显示 返回指定年份中指定月份的天数。[Visual Basic] Public Shared Function DaysInMonth( _ ByVal year As Integer, _ ByVal month As Integer _ ) As Integer[C#] public static int DaysInMonth( int year, int month );[C++] public: static int DaysInMonth( int year, int month );[JScript] public static function DaysInMonth( year : int, month : int ) : int;参数 year 年份。 month 月份(介于 1 到 12 之间的一个数字)。 返回值 指定 year 中 month 的天数。例如,如果 month 等于 2(表示二月),则返回值为 28 或 29,具体取决于 year 是否为闰年。异常 异常类型 条件 ArgumentOutOfRangeException month 小于 1 或大于 12。 示例 [Visual Basic, C#, C++] 下面的示例说明 DaysInMonth 方法。[Visual Basic] Const July As Integer = 7 Const Feb As Integer = 2' daysInJuly gets 31. Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)' daysInFeb gets 28 because the year 1998 was not a leap year. Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)' daysInFebLeap gets 29 because the year 1996 was a leap year. Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)[C#] const int July = 7; const int Feb = 2;// daysInJuly gets 31. int daysInJuly = System.DateTime.DaysInMonth(2001, July);// daysInFeb gets 28 because the year 1998 was not a leap year. int daysInFeb = System.DateTime.DaysInMonth(1998, Feb);// daysInFebLeap gets 29 because the year 1996 was a leap year. int daysInFebLeap = System.DateTime.DaysInMonth(1996, Feb);
其实我知道你的意思:
你可以这样来:把你的如:2004/2/29 赋值给 DateTimePicker.MinDate or MaxDate
因为非闰年的二月没有29所以如果是2003年就会抛出异常;往下的你应该知道怎么做了。
大月小月可以使用相同的方法;只要检验有没有31不就成了。
// http://www.aisto.com/roeder/dotnet,
// [email protected]
应该会有一些相关信息
DateTime 结构 | DateTime 成员 | System 命名空间 | DateTime 成员(Visual J# 语法) | C++ 托管扩展编程
要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准
语言
C#C++JScriptVisual Basic全部显示
返回指定年份中指定月份的天数。[Visual Basic]
Public Shared Function DaysInMonth( _
ByVal year As Integer, _
ByVal month As Integer _
) As Integer[C#]
public static int DaysInMonth(
int year,
int month
);[C++]
public: static int DaysInMonth(
int year,
int month
);[JScript]
public static function DaysInMonth(
year : int,
month : int
) : int;参数
year
年份。
month
月份(介于 1 到 12 之间的一个数字)。
返回值
指定 year 中 month 的天数。例如,如果 month 等于 2(表示二月),则返回值为 28 或 29,具体取决于 year 是否为闰年。异常
异常类型 条件
ArgumentOutOfRangeException month 小于 1 或大于 12。 示例
[Visual Basic, C#, C++] 下面的示例说明 DaysInMonth 方法。[Visual Basic]
Const July As Integer = 7
Const Feb As Integer = 2' daysInJuly gets 31.
Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)' daysInFeb gets 28 because the year 1998 was not a leap year.
Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)' daysInFebLeap gets 29 because the year 1996 was a leap year.
Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)[C#]
const int July = 7;
const int Feb = 2;// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth(2001, July);// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth(1998, Feb);// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System.DateTime.DaysInMonth(1996, Feb);