⑴ JavaScript访问时间限制问题
if写法错了
function clowin(){
var today=new Date()
var h=today.getHours()
if(0<=h && h<=6){
//if(0<=h<=6){
alert('亲爱的朋友,现在是休息时间,暂时不能访问主页!');
history.back();
}
else if(22<=h && h<=24){
//else if(22<=h<=24){
alert('亲爱的朋友,现在是休息时间,暂时不能访问主页!');
history.back();
}
}
-------------------------------------------
if(0<=h && h<=6)
else if(22<=h && h<=24)
⑵ js中日期格式控制,请教大家
直接的话是不行的,需要进行计算。
下面有个参考的示例
<html>
<head>
<title>日期判断 周 月 季 年</title>
<script type="text/javascript">
var getMonthWeek = function (a, b, c) {
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math.ceil( (d + 6 - w) / 7 );
};
var getYearWeek = function (a, b, c) {
var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 );
};
var today = new Date();//获取当前时间
var y = today.getFullYear();
var m = today.getMonth()+1;
var d = today.getDate();
document.write("今天是:",y,"-", m, "-", d, "<br/>");
document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" );
document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" );
var quarter = "";
var result = getYearWeek(y, m, d);
if (m <4) {
quarter = 1;
week = result;
} else if (m < 7) {
quarter = 2;
week = result - getYearWeek(y, 4, 1);
var day = new Date(y, 4, 1);
if (day.getDay() > 1) {
week += 1;
}
} else if (m < 10) {
quarter = 3;
week = result - getYearWeek(y, 7, 1);
var day = new Date(y, 7, 1);
if (day.getDay() > 1) {
week += 1;
}
} else {
quarter = 4;
week = result - getYearWeek(y, 10, 1);
var day = new Date(y, 10, 1);
if (day.getDay() > 1) {
week += 1;
}
}
document.write( "今天是第",quarter,"季度的第 ", week, " 周" );
</script>
</head>
<body>
</body>
</html>
⑶ 请问js如何控制输入日期范围在一个月之内
var d1 = document.getElementById("Text1").value;
var myDate1 = new Date();
myDate1.setFullYear(d1.substring(0, 4), d1.substring(4, 6), d1.substring(6));
var d2 = document.getElementById("Text2").value;
var myDate2 = new Date();
myDate2.setFullYear(d2.substring(0, 4), d2.substring(4, 6), d2.substring(6));
alert((myDate2 - myDate1)/86400000);
⑷ js日期控件 限制选择日期(只能选择指定日期)
js日期控件 限制选择日期(只能选择指定日期)
日期空间 貌似都有限制的功能
⑸ 如何用js来对输入日期的时间范围进行限制
把你的字符串分成年、月、日三部分,转成数字
然后用 var time=new Date(年,月,日); 来取得时间,再进行比较操作。注意月是0到11范围
⑹ js验证日期间隔不能大于一个月
还是你啊
刚才我也没想到
这样改:
var d1="20110911";
var d2="20111012";
var h1=parseInt(d1.substring(4,6),10);//转换成10进制int类型
var h2=parseInt(d2.substring(4,6),10);
alert(h2-h1);
if(h2-h1)>1
{
//你的代码
}
你要判断下年份,不然到年末出错
⑺ 求高手的JavaScript日期校验。要求起始日期不得大于结束日期。日期格式为:dd/mm/yyyy
<script type="text/javascript">
function today(){
var dd, ss="";
dd = new Date();
ss += dd.getYear()+"/";
ss += (dd.getMonth() + 1) + "/";
ss += dd.getDate();
return ss;
}
function comptime(beginTime,endTime){
var beginTimes=beginTime.substring(0,10).split('/');
var endTimes=endTime.substring(0,10).split('/');
beginTime=beginTimes[1]+'/'+beginTimes[2]+'/'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'/'+endTimes[2]+'/'+endTimes[0]+' '+endTime.substring(10,19);
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
if(a<0){
return -1;
}else if (a>0){
return 1;
}else if (a==0){
return 0;
}else{
return 'exception'
}
}
alert(comptime("2010/01/01",today()));
alert(comptime("2010/08/01",today()));
</script>
++++++++++++++++++++++++++++++++++++++++
我已经写出了时间对比的函数,你只需要把想要对比的时间放入函数跑一下就行了,有更多问题,可以直接HI我,。。。
至于楼主的时间格式,可以在这个JS里边改下时间顺序即可。。。。
记得加分。。。
⑻ 求限制时间段访问页面的JS代码
<SCRIPT LANGUAGE="JavaScript">
<!--
var d, s ;
d = new Date();
s = d.getDate() ;
if(s>17 || s<15){
alert("现在是上班时间。。。。。。");
window.close();
}
//-->
</SCRIPT>
测试无错误。
满意请采纳!
⑼ js验证日期格式mm-dd-yyyy,例如月份不要超过12
<!DOCTYPEHTML>
<html>
<head>
<metacharset="UTF-8"/>
<title>JS</title>
<STYLE>
</STYLE>
<scripttype="text/javascript">
window.onload=function()
{
vardate=newDate,year=date.getFullYear();
if(year%400==0||year%4==0&&year%100!=0)
{
alert('今年是闰年');
}
else
{
alert('今年不是闰年');
}
varreg=/^(0[1-9]|1[0-2])-(0[1-9]|[12]d|3[01])-[1-9]d{3}$/;
varstr="12-01-2011";
alert(reg.test(str));
str="13-01-2011";
alert(reg.test(str));
}
</script>
</head>
<body>
</body>
</html>