【JS】指定日期与当前日期比较问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了【JS】指定日期与当前日期比较问题相关的知识,希望对你有一定的参考价值。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function $()return document.getElementById(arguments[0])||false;
String.prototype.replaceAll = function(s1,s2)
return this.replace(new RegExp(s1,"gm"),s2);
function getd()
if($('t1').value==""&&$('t2').value=="")
alert('必须填写一个时间');
return false
else
apptime = $('t1').value.replace(/-/g,"/");
retime= $('t2').value.replace(/-/g,"/");
var nowtime=new Date();//取今天的日期
var d1 = new Date(Date.parse(apptime));
var d2 = new Date(Date.parse(retime));
if($('t1').value!=""&&d1<nowtime)
alert('【预约时间】不能比当前时间更早');
return false;
if($('t2').value!=""&&d2<nowtime)
alert('【提醒时间】不能比当前时间更早');
return false;
</script>
<script language="javascript" src="script/Calendar.js"></script>
<script type="text/javascript">
var c = new Calendar("c");
document.write(c);
</script>
</head>
<body>
<input type="submit" id="bt1" onclick="return getd();" />
<input type="text" name="t1" onClick="c.showMoreDay = false;c.show(this);" size="15" id="t1" />
<input type="text" name="t2" onClick="c.showMoreDay = false;c.show(this);" size="15" id="t2" />
</body>
</html>
选择的日期格式为yyyy-MM-dd 运行以后不知道为什么选择当前日期也不满足条件,请高手帮忙指点一下 谢谢
<script type="text/javascript">
function writeDateInfo()
var day="";
var month="";
var ampm="";
var ampmhour="";
var myweekday="";
var year="";
mydate=new Date();
myweekday=mydate.getDay();
mymonth=mydate.getMonth()+1;
myday= mydate.getDate();
myyear= mydate.getYear();
year=(myyear > 200) ? myyear : 1900 + myyear;
if(myweekday == 0)
weekday=" 星期日";
else if(myweekday == 1)
weekday=" 星期一";
else if(myweekday == 2)
weekday=" 星期二";
else if(myweekday == 3)
weekday=" 星期三";
else if(myweekday == 4)
weekday=" 星期四";
else if(myweekday == 5)
weekday=" 星期五";
else if(myweekday == 6)
weekday=" 星期六";
document.write(year+"年"+mymonth+"月"+myday+"日"+weekday);
writeDateInfo();
</script></FONT></LI></UL></div>
<script type='text/javascript'>
<!--
ShowClass(2);
//-->
</script>
结果为::2011年3月11日 星期四
以上是关于【JS】指定日期与当前日期比较问题的主要内容,如果未能解决你的问题,请参考以下文章