...

View Full Version : Resolved Countdown based on server's time



[vengeance]
12-01-2009, 02:06 PM
Hey.

I'm currently looking for a countdown script, which is based on the server's time. I've only found scripts, that's based on the local computer's time, which means the output of the script changes, when the time on the computer is changed.

And I want to make a public announcement which counts down to something - and should output the same at every person.

I'm not that familiar with JavaScript, I know some jQuery - if anyone can supply any links or can help me with this, I'd appreciate it.

oesxyl
12-01-2009, 03:21 PM
;894151']Hey.

I'm currently looking for a countdown script, which is based on the server's time. I've only found scripts, that's based on the local computer's time, which means the output of the script changes, when the time on the computer is changed.

And I want to make a public announcement which counts down to something - and should output the same at every person.

I'm not that familiar with JavaScript, I know some jQuery - if anyone can supply any links or can help me with this, I'd appreciate it.
what's the problem with gmt?

best regards

[vengeance]
12-01-2009, 03:49 PM
what's the problem with gmt?

best regards

Sorry, but I didn't mention anything regarding GMT time?
My server runs on GMT +1 by default. And I want a count down script that relies on the server's time itself, not the local computer.

For example, if the time's 1:30 then the countdown script would output something. If I change the time back to 1:15 the countdown script would output something else... a bigger number because we've "gone back in time".

Hope I made that clearer this time. :)

Philip M
12-01-2009, 04:01 PM
what's the problem with gmt?

best regards

UTC time is universal time (formerly GMT).

Here is an example which will show the PST time (GMT-8) in all browsers regardless of the user's local time.
You would wish to use GMT+1.


<script type = "text/javascript">

var dateobj = new Date();
var hrs = dateobj.getUTCHours()-8; // offset GMT - PST
if (hrs < 0) {hrs = hrs + 24}
var mins = dateobj.getUTCMinutes();
if (mins <10) {mins = "0" + mins}
var secs = dateobj.getUTCSeconds();
if (secs <10) {secs = "0" + secs}
var currenttime = hrs+":"+mins+":"+secs; //create time string
alert (currenttime);

</script>


If you want some artificial time that you can alter in some way then you have no alternative but to user server-side scripting. Javascript is a client-side language and cannot interact with the server.

oesxyl
12-01-2009, 04:05 PM
;894193']Sorry, but I didn't mention anything regarding GMT time?
no you didn't mention, I mention, :)
I apologise that was not clear, why you don't use gmt?


My server runs on GMT +1 by default. And I want a count down script that relies on the server's time itself, not the local computer.

For example, if the time's 1:30 then the countdown script would output something. If I change the time back to 1:15 the countdown script would output something else... a bigger number because we've "gone back in time".

Hope I made that clearer this time. :)
yes is more clear but I have same question, :)
you want to countdown the time from the moment when a visitor request a page to a given time moment. If you use gmt doesn't matter the local time of the visitor.
Let's say you want to stop at 3:00 gmt. If a user request the page at 1:30 gmt, will countdown for 1 hour and 30 min but if user time is 1:15 gmt will be 1 hour and 45 min.
Doesn't matter local time of the visitor or server, :)

best regards

[vengeance]
12-01-2009, 05:19 PM
no you didn't mention, I mention, :)
I apologise that was not clear, why you don't use gmt?


yes is more clear but I have same question, :)
you want to countdown the time from the moment when a visitor request a page to a given time moment. If you use gmt doesn't matter the local time of the visitor.
Let's say you want to stop at 3:00 gmt. If a user request the page at 1:30 gmt, will countdown for 1 hour and 30 min but if user time is 1:15 gmt will be 1 hour and 45 min.
Doesn't matter local time of the visitor or server, :)

best regards

I see. Do you have any examples of how I could achieve this? Afterall, I have barely any knowledge of JavaScript.

oesxyl
12-01-2009, 05:33 PM
;894246']I see. Do you have any examples of how I could achieve this? Afterall, I have barely any knowledge of JavaScript.
ok, I will prepare an example.

best regards

oesxyl
12-01-2009, 07:28 PM
;894246']I see. Do you have any examples of how I could achieve this? Afterall, I have barely any knowledge of JavaScript.



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Countdown timer test</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<p id="msgid"></p>
</body>
</html>




/* -*- c++ -*- */
var evdatetime = '12/01/2009 19:21 GMT';
var evdt = new Date(evdatetime);
var tdiff = 10000;

function diff2int(){
var now = new Date();
return Math.floor((evdt.getTime() - now.getTime())/1000);
}

function diff2str(){
tdiff = diff2int();
var diff = tdiff;
var s = diff % 60;
diff = (diff - s)/60;
var m = diff % 60;
diff = (diff - m)/60;
var z = diff % 24;
diff = (diff - z)/24;
return (diff + ':' + z + ':' + m + ':' + s);
}

function makeitmove(){
var txtcnt = document.getElementById('msgid');
var txtmsg = ['Time until I go: ','Ok, I&apos;m out'];
var now = new Date();
if(txtcnt){
if(tdiff > 0){
txtcnt.innerHTML = txtmsg[0] + diff2str();
txtcnt.innerHTML += '<br />' + now.toUTCString();
txtcnt.innerHTML += '<br />' + evdt.toUTCString();
}else{
txtcnt.innerHTML = txtmsg[1];
}
}
}

window.onload = function(){
setInterval(makeitmove,1000);
};


best regards

[vengeance]
12-01-2009, 10:28 PM
@oesxyl: Thank you so much for taking your time to write this! It works great and easy for me to understand aswell.

Kudos to you! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum