Jump to content


Photo

Clock not in form box?


  • Please log in to reply
7 replies to this topic

#1 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 12 May 2006 - 07:26 PM

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
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#2 eXtaZa

eXtaZa
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 May 2006 - 01:26 PM

Are you meaning this:

<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>

?

#3 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 13 May 2006 - 05:06 PM

That'll do the trick! Is it going off my server time or the user's computer's time?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 eXtaZa

eXtaZa
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 May 2006 - 05:32 PM

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...

#5 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 13 May 2006 - 05:38 PM

[!--quoteo(post=373545:date=May 13 2006, 12:32 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 12:32 PM) View Post[/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. :(
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#6 eXtaZa

eXtaZa
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 May 2006 - 06:21 PM

You can use the date funtion in php, its by the server time and its much more simple...

#7 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 13 May 2006 - 06:23 PM

[!--quoteo(post=373554:date=May 13 2006, 01:21 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 01:21 PM) View Post[/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.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#8 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 13 May 2006 - 06:50 PM

<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>

This is what I got, I checked it by setting my computer timezone differently and it works.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users