Javascript to control time

I need some help with this set of javascript codes.
some background:
code is suppose to restrict access using time constraint.
I need the codes such that between 1200 to 1400 and 1800 to 0830, the link is open else hide link.
problem with my current codes:
I’m using getHours, as such i’m not able to implement the 1800 to 0830 because of the 30 mins. Is there any help with this???
Can i add in another additional code to code the mins??

var d = new Date();
var t = d.getHours();
if((9<=t && hr<=12 || (14<=t && t<=18)){
hideLink();
}
}
function hideLink(){

Yes you can. You know about getHours, well check out the Date documentation to see the other methods that you can use.

[ot]Did someone ask about controlling time?

/Dr Who[/ot]
:smiley:

check out the documentation is a good idea!

One thing worth considering is that the time JavaScript sees is the time on your visitor’s computer. That will vary depending on where they are in the world and whether they have the time set correctly or not. Also somewhere between 6 and 10% of your visitors will not have JavaScript at all.Therefore you cannot use JavaScript to restrict access to anything.

If you want to restrict access you should look into a server side solution.

Does it change things to presume that he’s working on a company-based intranet kinda deal?
Older post: http://www.sitepoint.com/forums/showthread.php?t=649642

It would still be better to do it server side in that case but yes it does change things to at least make it workable provided that people don’t have access to change the time on their computer.

var d = new Date();
var t = d.getHours() + d.getMinutes()/60;
if((8.5<=t && t<=12) || (14<=t && t<=18)){
hideLink();
}
}
function hideLink(){

Yea. I’m working on an intranet in fact. Thanks all for the help! really appreciate that! :slight_smile: