Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2007, 06:44 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am not forgetting about you, but I have some things to do this evening, i will play with this later.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
 
Old February 5th, 2007, 07:27 PM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have found a simple javascript clock that seems to work, however its time is gathered from the users computer. how can i adjust it to grab the time from the server instead? this may be easier to answer, if not forget i even mentioned it!

code;

<div id="js_clock" class="clock">
<script language="javascript">
function js_clock(){
var clock_time = new Date();
var clock_hours = clock_time.getHours();
var clock_minutes = clock_time.getMinutes();
var clock_seconds = clock_time.getSeconds();
var clock_suffix = "AM";

if (clock_hours > 11){clock_suffix = "PM";clock_hours = clock_hours - 12;}
if (clock_hours == 0){clock_hours = 12;}
if (clock_hours < 10){clock_hours = clock_hours;}
if (clock_minutes < 10){clock_minutes = "0" + clock_minutes;}
if (clock_seconds < 10){clock_seconds = "0" + clock_seconds;}

var clock_div = document.getElementById('js_clock');clock_div.inne rHTML = clock_hours + ":" + clock_minutes + ":" + clock_seconds + " " + clock_suffix;setTimeout("js_clock()", 1000);}js_clock();</script></div>

New to this planet
 
Old February 5th, 2007, 08:08 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You need to understand that since javascript is Client Side technology, when you call: new Date() it takes the time and date from the users PC, not the server since the script is running on the client, not the server.

However, you can meld these 2 scripts together. Keep the code in your most recent post add this to the top of the page:
<%@ LANGUAGE="JavaScript" %>
<%
/*** Clock -- beginning of server-side support code
by Andrew Shearer, http://www.shearersoftware.com/
v2.1-ASP, 2002-10-12. For updates and explanations, see
<http://www.shearersoftware.com/software/web-tools/clock/>. ***/

/* Prevent this page from being cached (though some browsers still
   cache the page anyway, which is why we use cookies). This is
   only important if the cookie is deleted while the page is still
   cached (and for ancient browsers that don't know about Cache-Control).
   If that's not an issue, you may be able to get away with
   "Cache-Control: private" instead. */
Response.AddHeader("Pragma", "no-cache");

/* Grab the current server time. */
var gDate = new Date();
/* Are the seconds shown by default? When changing this, also change the
   JavaScript client code's definition of clockShowsSeconds below to match. */
var clockShowsSeconds = false;

function getServerDateItems() {
    return gDate.getFullYear()+","+gDate.getMonth()+","+gDate .getDate()+","
        +gDate.getHours()+","+gDate.getMinutes()+","+gDate .getSeconds();
}

/*** Clock -- end of server-side support code ***/
%>

Then in your above code change this:
var clock_time = new Date();

to
var clock_time = new Date(<%=getServerDateItems()%>);

which should give you the correct server time.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
 
Old February 5th, 2007, 08:52 PM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for hanging in here with me, im just learning. anyway, your provided answer seems great, and even though it now appears to be grabbing the date from the server, the ticking clock part has again deactivated. you have to reload the page to update the clock. arrrgh! below is my complete code. if you have any more ideas, i would love to hear them. i am going home for the evening now, thanks again for yor help!

<html>
<head>
<title>JavaScript Clock Demo</title>

<%@ LANGUAGE="JavaScript" %>
<%

Response.AddHeader("Pragma", "no-cache");

var gDate = new Date();

function getServerDateItems() {
    return gDate.getFullYear()+","+gDate.getMonth()+","+gDate .getDate()+","
        +gDate.getHours()+","+gDate.getMinutes()+","+gDate .getSeconds();
}

%>

</head>
<style>
.clock {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#666666;
}</style>

<body>
<center>


<div id="js_clock" class="clock">
<script language="javascript">
function js_clock(){
var clock_time = new Date(<%=getServerDateItems()%>);
var clock_hours = clock_time.getHours();
var clock_minutes = clock_time.getMinutes();
var clock_seconds = clock_time.getSeconds();
var clock_suffix = "AM";

if (clock_hours > 11){clock_suffix = "PM";clock_hours = clock_hours - 12;}
if (clock_hours == 0){clock_hours = 12;}
if (clock_hours < 10){clock_hours = clock_hours;}
if (clock_minutes < 10){clock_minutes = "0" + clock_minutes;}
if (clock_seconds < 10){clock_seconds = "0" + clock_seconds;}

var clock_div = document.getElementById('js_clock');clock_div.inne rHTML = clock_hours + ":" + clock_minutes + ":" + clock_seconds + " " + clock_suffix;setTimeout("js_clock()", 1000);}js_clock();</script></div>


</center>
</body>
</html>

New to this planet





Similar Threads
Thread Thread Starter Forum Replies Last Post
Clock jeremy1048 Access 2 August 22nd, 2008 06:55 AM
ticking off records with an update query michael193nj Access 3 March 25th, 2008 10:47 AM
System Clock Program nsx2200 Visual Basic 2005 Basics 1 March 26th, 2007 04:11 AM
Displaying a clock hdfireftr Visual Basic 2005 Basics 2 September 15th, 2006 01:12 PM
Countdown clock Ciarano Beginning VB 6 1 March 12th, 2004 07:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.