老找不到日期比较函数,用来比较输入的日期必须比当前日期晚,但是要包括当天。所以就自己写了一个最笨的。先检测日期格式,在拆分比较,当然可以写在一起的。
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
function
strDateTime(str)
{
var r = str.match( / ^(\d{1,4})([-.]|\ / )(\d{ 1 , 2 })\ 2 (\d{ 1 , 2 })$ / );
if (r == null )
{
return false ;
}
var d = new Date(r[ 1 ], r[ 3 ] - 1 , r[ 4 ]);
return (d.getFullYear() == r[ 1 ] && (d.getMonth() + 1 ) == r[ 3 ] && d.getDate() == r[ 4 ]);
}
function CheckDateTime(str)
{
var r = str.match( / ^(\d{1,4})(.|\ / )(\d{ 1 , 2 })\ 2 (\d{ 1 , 2 })$ / );
if (r == null )
{
return false ;
}
var omm = str.substring( 5 ,str.lastIndexOf ( " . " ));
var odd = str.substring(str.length,str.lastIndexOf ( " . " ) + 1 );
var oyy = str.substring( 0 ,str.indexOf ( " . " ));
var now = new Date();
var nyy = now.getFullYear(),
nmm = now.getMonth() + 1 ,
ndd = now.getDate();
if (parseFloat(oyy) >= parseFloat(nyy))
{
if (parseFloat(omm) >= parseFloat(nmm))
{
if (parseFloat(odd) >= parseFloat(ndd))
{
return true ;
}
else
{
return false ;
}
}
else
{
return false ;
}
}
else
{
return false ;
}
}
{
var r = str.match( / ^(\d{1,4})([-.]|\ / )(\d{ 1 , 2 })\ 2 (\d{ 1 , 2 })$ / );
if (r == null )
{
return false ;
}
var d = new Date(r[ 1 ], r[ 3 ] - 1 , r[ 4 ]);
return (d.getFullYear() == r[ 1 ] && (d.getMonth() + 1 ) == r[ 3 ] && d.getDate() == r[ 4 ]);
}
function CheckDateTime(str)
{
var r = str.match( / ^(\d{1,4})(.|\ / )(\d{ 1 , 2 })\ 2 (\d{ 1 , 2 })$ / );
if (r == null )
{
return false ;
}
var omm = str.substring( 5 ,str.lastIndexOf ( " . " ));
var odd = str.substring(str.length,str.lastIndexOf ( " . " ) + 1 );
var oyy = str.substring( 0 ,str.indexOf ( " . " ));
var now = new Date();
var nyy = now.getFullYear(),
nmm = now.getMonth() + 1 ,
ndd = now.getDate();
if (parseFloat(oyy) >= parseFloat(nyy))
{
if (parseFloat(omm) >= parseFloat(nmm))
{
if (parseFloat(odd) >= parseFloat(ndd))
{
return true ;
}
else
{
return false ;
}
}
else
{
return false ;
}
}
else
{
return false ;
}
}