Jump to content

Archived

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

Jessica

Clock not in form box?

Recommended Posts

I've been trying to find a javascript clock, and all the ones I find by googling are in forms in the input field type. Does anyone know how I would do this without putting it in a form?

Thanks

Share this post


Link to post
Share on other sites
Are you meaning this:

[code]
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10)
  {i="0" + i}
  return i
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
[/code]

?

Share this post


Link to post
Share on other sites
That'll do the trick! Is it going off my server time or the user's computer's time?

Share this post


Link to post
Share on other sites
I think that by the user's computer time... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
But I don't know exacly...

Share this post


Link to post
Share on other sites
[!--quoteo(post=373545:date=May 13 2006, 12:32 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 12:32 PM) [snapback]373545[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think that by the user's computer time... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
But I don't know exacly...
[/quote]

yeah..it is the user's. My fiance is trying to help me get it to display server time, or at least just the same time for everyone, we want it in CST. :(

Share this post


Link to post
Share on other sites
You can use the date funtion in php, its by the server time and its much more simple...

Share this post


Link to post
Share on other sites
[!--quoteo(post=373554:date=May 13 2006, 01:21 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 01:21 PM) [snapback]373554[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use the date funtion in php, its by the server time and its much more simple...
[/quote]

but then the clock isn't dynamic.

Share this post


Link to post
Share on other sites
[code]<div id="clock">
<script language="javascript">

  // Get the server time and GMT offset
  var server_offset = <? print(date('Z')); ?>;
  var server_time = <? print(time()); ?>;

  // The clock DIV
  var clock = document.getElementById("clock");

  // Get the client GMT offset
  var client_offset = new Date();
  client_offset = client_offset.getTimezoneOffset() / 60;

  // Get the appropriately mapped time
  var client_time = server_time;

  var clock = document.getElementById("clock");
  var client_time = server_time;

  function js_clock() {

    var date_time = new Date((client_time * 1000));
    var date      = date_time.getDate();
    var month     = date_time.getMonth() + 1;
    var year      = date_time.getFullYear();
    var hours     = date_time.getHours()+(client_offset-5);
    var minutes   = date_time.getMinutes();
    var seconds   = date_time.getSeconds();
    var suffix    = "AM";

    if(hours > 11){
        suffix = "PM";
        hours = hours - 12;
    }
    if(hours == 0){
        hours = 12;
    }
    if(hours < 10){
        hours = "0" + hours;
    }
    if(minutes < 10){
        minutes = "0" + minutes;
    }
    if(seconds < 10){
        seconds = "0" + seconds;
    }
    if(month < 10){
        month = "0" + month;
    }

    clock.innerHTML = hours + ":" + minutes + ":" + seconds + " " + suffix;

    client_time++;

    setTimeout("js_clock()", 1000);      

  }              

  js_clock();

</script>
</div>[/code]

This is what I got, I checked it by setting my computer timezone differently and it works.

Share this post


Link to post
Share on other sites

×

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.