Jump to content

Time sensitive


Excitus

Recommended Posts

I need the text to appear from 16:30 to 8:30 the next days.

Thats all I have worked out :( but the time is inv3erted and Im missing minutes...

 

<html>

<head>

</head>

<body>

<script>

var curdate = new Date();

if (curdate.getHours() >= 8 && curdate.getHours() < 20)

alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report');

</script>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/88659-time-sensitive/
Share on other sites

 

You just needed to flip some stuff around:

 

<html>
<head>
</head>
<body>
<script>
var curdate = new Date();
if (curdate.getHours() >= 8 && curdate.getHours() < 20) {
// error is not given because you are open
}
else {
alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report'); 
}
</script>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/88659-time-sensitive/#findComment-454037
Share on other sites

 

try this; it may not work, but check and see:

 

<html>
<head>
</head>
<body>
<script>
var curdate = new Date();
if (curdate.getHours() >= 8.5 && curdate.getHours() < 20.5) {
// error is not given because you are open
}
else {
alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report'); 
}
</script>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/88659-time-sensitive/#findComment-454056
Share on other sites

Not to burst anyone's bubble, but using JavaScript for this type of display calculation requires that you are dependent upon your client time being accurately set. JavaScript pulls the system time, so if someone has their time set to one different than yours, or if they have their timezone offset differently than yours, you'll always have it show during THEIR 16:30 - 8:30.

Link to comment
https://forums.phpfreaks.com/topic/88659-time-sensitive/#findComment-454330
Share on other sites

The time set or time zone is not really that big of an issue.

What i'm more concerned about is, not having an alert (popup), but more as a text on the site shown between does hours?!

 

Possible??

 

 

Don't use alert(), but rather use document.write()... or even better, put a div with an id where you want your message to show and update the content. For instance, have something like this in the page: <div id="messageDiv"></div>

 

Then, you can access is like this:

document.getElementById('messageDiv').innerHTML = "My Message!!!";

Link to comment
https://forums.phpfreaks.com/topic/88659-time-sensitive/#findComment-454363
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.