问一个 判断时间的代码 最好是 JS版的
要求 输入时间 必须大于或者等于今天 否则不让输入
时间格式2008-05-09
要求 输入时间 必须大于或者等于今天 否则不让输入
时间格式2008-05-09
解决方案 »
- event.screenX; 监视器振幅 ,不会吧,screenY呢?》
- 为什么有时新增文件,VSS不会自动签出项目,其他人就获取不到新文件?
- DropDownList的Attributes.Add("","")方法怎么在页面呈现之前在页面中添加事件?
- 问个服务器的问题。
- 孟子e章,小山,慕白兄或是对ajax有研究的人请进
- 想给blog加个统计访问量的功能,要求防刷新,谁有?(100分)
- Application.Set
- asp.net和asp的session的值不通用的,那怎样实现asp.net与asp的会话?请大虾指教
- “/web”应用程序中的服务器错误。
- 发票 套打asp.net(c#) 方案求解
- GridView如何定义一个DATAKEY为一个或多个主关键字
- 怎样获得别的用户的profile
JS先获取当前时间
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
var nd = year + "-" + month + "-" + date;
var ld = 输入时间;
nd = new Date(nd.replace("-", "/"));
ld = new Date(ld.replace("-", "/"));
if (Date.parse(ld) - Date.parse(nd ) < 0) {
alert("输入时间小于当前时间");
return false;
} 以上代码没测试过。楼主试下
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
var nd = year + "-" + month + "-" + date;
var ld = "2008-5-24";
nd = new Date(nd.replace("-", "/"));
ld = new Date(ld.replace("-", "/"));
if (Date.parse(ld) - Date.parse(nd ) < 0) {
alert("输入时间小于当前时间");
} else{
alert("输入时间大于当前时间");
}
不好意思。刚才now忘记定义了 你再试下
var times= "2008-05-09:;
times = times.replace("-","");
把当前日期也同上去掉-,然后两个数直接对比
又忘记了
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
month = month +1;
var nd = year + "-" + month + "-" + date;
var ld = "2008-5-24";
nd = new Date(nd.replace("-", "/"));
ld = new Date(ld.replace("-", "/"));
if (Date.parse(ld) - Date.parse(nd ) < 0) {
alert("输入时间小于当前时间");
} else{
alert("输入时间大于当前时间");
}
var _date = document.getElementById("txtDate").value;
if(!/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(_date)){
alert("日期格式不正确");
return;
}
var now = new Date();
var now_days = now.getYear()*365+now.getMonth()*30+now.getDate();
var input_days = parseInt(_date.split('-')[0])*365+parseInt(_date.split('-')[1])*30+parseInt(_date.split('-')[2]);
if(input_days<now_days){
alert("输入日期不能小于当前日期");
return;
}
var a=/^(\d{4})\-(\d{1,2})\-{\d{1,2}}$/g;
var b=*//你获得的日期 就是用户自己输入的
var t=new Date();
var year=t.getYear();
var month=t.getDate();
var day=t.getDay();
var str
result=b.match(a);
len=
if(result!=null)
{
if (parseInt(result[0])>=year)
{return true;
}
else
{
return false;
}
if(parseInt(result[0])==year&&parseInt(result[1]>=month))
{return true;}
else
{return false;}
if(parseInt(result[0])==year&&parseInt(result[1]==month)&&parseInt(result[2])>=day)
{...
}
else
{...}}
else
{return false;}
function test()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
month = month +1;
var nd = year + "-" + month + "-" + date;
var ld = "2008-5-24";
nd = ld.replace("-","");
ld = ld.replace("-","");
if (Date.parse(ld) - Date.parse(nd ) < 0) {
alert("输入时间小于当前时间");
} else{
alert("输入时间大于当前时间");
} }
//这段代码,我试了下FF也可以的
如果不行看下是不是你的FF问题
try
{
Convert.ToDateTime(this.txtStartTime.Text);
if(Convert.ToDateTime(this.txtStartTime.Text).ToShortDateString().CompareTo(DateTime.Now.ToShortDateString())==0 || Convert.ToDateTime(this.txtStartTime.Text).ToShortDateString().CompareTo(DateTime.Now.ToShortDateString())==1)
{
//执行代码
}
}
catch
{
Response.Write("<script>alert()</script>");
Response.End();
}
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
month = month +1;
var nd = year + "-" + month + "-" + date;
取不到时间
{
var pattern = /^\s*((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))\s*$/;
if(pattern.test(strData))
{
return true;
}
else
{
return false;
}
}
var now=new Date();
var year=now.getFullYear();
var month=now.getUTCMonth()+1;
var date=now.getDate();
// month = month +1;
var nd = year + "-" + month + "-" + date;
alert(nd);
var ld = "2008-5-28";
alert(ld);
if (ld<nd)
{
alert("输入时间小于当前时间");
}
else
{
alert("输入时间大于当前时间");
--------------------------------------
ff下测试通过!
}
</script>
var month=now.getMonth()+1;
PS:LS的都是牛人,小弟佩服,人笨,觉得没那必要搞那么复杂吧/