MVC 2的开始日期和结束日期验证 [英] mvc 2 start date and end date validation
本文介绍了MVC 2的开始日期和结束日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我想要比较两个日期,因为某些原因如下code将返回false,如果我指定25/05/2012(开始日期)和31/05/12(截止日期)。
Hi guys i'm trying to compare two dates, for some reason the following code will return false, if i specify 25/05/2012 (startdate) and 31/05/12 (end date).
如果25日作为起始日期这只发生,如果我用26日正常工作。
This only happens if 25th is used as the start date, works fine if i use 26th.
public bool IsValidDate(DateTime startDate, DateTime endDate)
{
return startDate < endDate && endDate > startDate;
}
有什么地方出错了?
what could be wrong?
推荐答案
您一定是搞错了什么。对于给定的输入您指定此code返回真正
:
You must be mistaken something. For the given input you specified this code returns true
:
class Program
{
static void Main()
{
var startDate = new DateTime(2012, 5, 25);
var endDate = new DateTime(2012, 5, 31);
Console.WriteLine(IsValidDate(startDate, endDate));
}
public static bool IsValidDate(DateTime startDate, DateTime endDate)
{
return startDate < endDate && endDate > startDate;
}
}
打印真正
在控制台上。
现在当然重复完全相同的条件下两次是没有意义的。一旦陈述病情是绰绰有余的:
Now of course repeating the exact same condition twice is meaningless. Stating the condition once is more than enough:
public bool IsValidDate(DateTime startDate, DateTime endDate)
{
return startDate < endDate;
}
这篇关于MVC 2的开始日期和结束日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文