Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing the Server Time

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
Hi everyone,

I am a beginner at javascript, and I'm having some troubles with a script I'm trying to use.

I downloaded a countdown script which works great... however, it's using the user's time on their computer to reference the countdown, but I need everyone's countdown to be the same, even if their computer's clock is a little off, or if they are in a different time zone.

I need to know how to use the SERVER's clock instead of the user's clock - is there a way? Here is the code I am currently using:

var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+&quot; &quot;+todayd+&quot;, &quot;+todayy+&quot; &quot;+todayh+&quot;:&quot;+todaymin+&quot;:&quot;+todaysec
futurestring=montharray[mo-1]+&quot; &quot;+da+&quot;, &quot;+yr+&quot; &quot;+hr+&quot;:&quot;+minute+&quot;:&quot;+sec

Is there an easy way to do this?
Thanks in Advance!!!
 
The easiest way would be to do it with VBscript and change your file to a asp page. As long as your server supports them.

it would look something like this.
<%response.write(date())%>.
<%response.write(time())%>.
provide tools to let people become their best.
 
Thanks onpnt for your quick response!

The server I'm using does not support ASP. Does it have to be a server-side scripting/programming language used to grab the server computer's date and time? Does this mean that client-side scripts can only grab the user's date and time? I am using ColdFusion for the rest of the site, so I can easily grab the current time off the server, however it's a countdown script, so the javascript checks the time and date every second and counts it down. If I get the server's time using ColdFusion, it does not count down anymore (because CF just checked the time once when it loaded the page).
 
As far as I know (I'm sure there's a way for everything) you can't do what you want with the server without some kind server side code. provide tools to let people become their best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top