PDA

View Full Version : alarm clock scripts


peke
03-01-2006, 07:45 PM
hey,

i want to make a time controled text.

ex.: between 18.05 hour and 20.45 hour the text must be server on line

between 20.45 and 18.05 (the next day) the text must change to server off line

the text must be accurate from the minut your vieuwing your html page.
ex.: i'm vieuwing the page at 18.08 it must say : server on line.

im woundring about this for 10 to 15 days; and everything i try woudn't work

can anyone help me?

thx Peke

(srry for bad english)

Philip M
03-01-2006, 08:09 PM
<SCRIPT type = "text/javascript">
var message = "Off Line";
var now= new Date();
var hh = now.getHours();
var mm = now.getMinutes();
if (hh==18 && mm >= 5) {message = "On Line"}
if (hh==19) {message = "On Line"}
if (hh==20 && mm <=45) {message = "On Line"}
alert (message);
</SCRIPT>

Is that what you want? Note that the time is GMT - you may need to allow for this or use local time.

Also, this applies to the time that the page was loaded. If you want to change the status message while the user is on line then you need to make it into a function to be called periodically.

ubik
03-01-2006, 09:27 PM
hey can you post once the accurate time in your area once? I want to try and write something like this for myself as well.

Kor
03-02-2006, 11:30 AM
Try this. In theory it should work. You have to adjust manually each time when the the summer hour of the server Local Time is added or not.

The code should work according to the server's Local Time. That means it will show "Server On Line" each day, at 20:05 server's Local Time (the user's time could be other). The code will check the time each 1 minute.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var hon=18;var mon=5;
var hoff=20;var moff=45;
var delay = 60000;// milliseconds
var summerhour=0;// If Summer Hour =1
function check(){
var today=new Date()
var GMT=today.getTimezoneOffset();
var y=today.getFullYear();
var m=today.getMonth();
var d=today.getDate();
var servOn=new Date(y,m,d,hon,mon-GMT+(summerhour*60));
var servOff=new Date(y,m,d,hoff,moff-GMT+(summerhour*60));
var mes =(today>servOn&&today<servOff)?'Server On Line':'Server Off Line';
document.getElementById('mymes').firstChild.data=mes;
setTimeout('check()',delay)
}
onload = check
</script>
</head>
<body>
<span id="mymes">&nbsp;</span>
</body>
</html>