Current location: Hot Scripts Forums » General Community » Script Requests » Custom Clock


Custom Clock

Reply
  #1 (permalink)  
Old 04-30-08, 07:00 PM
lordtopcat lordtopcat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Custom Clock

Hi Guys,

I want a simple digital clock that I can put on my webpage, the only thing is, I want to be able to configure what timezone it displays, so as everyone who enters the page sees the same time.

Thank you!
LTC
Reply With Quote
  #2 (permalink)  
Old 05-02-08, 07:32 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
This simple clock gets its time from the clients computer. So no matter where they are in the world, it will show their time.
Javascript Code:
  1. <html>
  2. <head>
  3. <style>
  4. .clock_container
  5. {
  6.  width:100px;
  7.  text-align:center;
  8.  background:#000000;
  9.  border:4px solid #ff0000;
  10.  padding:2px;
  11.  }
  12. .cw
  13. {
  14.  color:#ffff00;
  15.  font-weight:bold;
  16.  }
  17. .pr{padding-right:2px;}
  18. </style>
  19. <script language="javascript">
  20. function simple_clock(){
  21. ourDate = new Date();
  22. var seconds=ourDate.getSeconds();
  23. seconds=seconds+"";
  24. if(seconds.length==1){seconds="0"+seconds;}
  25. var minutes=ourDate.getMinutes();
  26. minutes=minutes+"";
  27. if(minutes.length==1){minutes="0"+minutes;}
  28. var hours=ourDate.getHours()
  29. document.getElementById("hours").innerHTML=hours;
  30. document.getElementById("min").innerHTML=minutes;
  31. document.getElementById("sec").innerHTML=seconds;
  32. }
  33. setInterval("simple_clock()",500);
  34. </script>
  35. </head>
  36. <body>
  37. <div class="clock_container">
  38.  <span id="hours" class="cw pr"></span>
  39.  <span class="cw">:</span>
  40.  <span id="min" class="cw pr"></span>
  41.  <span class="cw">:</span>
  42.  <span id="sec" class="cw"></span>
  43. </div>
  44. </body>
  45. </html>
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 05-03-08, 05:43 AM
lordtopcat lordtopcat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, but I want to display the same time for EVERYONE. I don't want to get the client's time.

Thank You though
Reply With Quote
  #4 (permalink)  
Old 05-03-08, 06:18 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Do you have PHP?
__________________
Jerry Broughton
Reply With Quote
  #5 (permalink)  
Old 05-04-08, 06:27 AM
lordtopcat lordtopcat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Yes. I am currently programming the page I want to display the clock in php.
Reply With Quote
  #6 (permalink)  
Old 05-04-08, 08:21 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Ok, You need to files to make this happen.

First the HTML file.

Put this code in your HTML file.
HTML Code:
<html>
<head>
<style>
.clock_container
{
 width:100px;
 text-align:center;
 background:#000000;
 border:4px solid #ff0000;
 padding:2px;
 }
.cw
{
 color:#ffff00;
 font-weight:bold;
 }
.pr{padding-right:2px;}
</style>
<script>
function createRequest()
{
 var xmlhttp = false;
 try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(E){xmlhttp = false;}}
 if(!xmlhttp && typeof XMLHttpRequest!='undefined'){try{xmlhttp = new XMLHttpRequest();}catch(e){xmlhttp=false;}}
 if(!xmlhttp && window.createRequest){try{xmlhttp = window.createRequest();}catch(e){xmlhttp=false;}}
 return xmlhttp;
 }
function request_time()
{
 var url = "get_time.php";
 var con=createRequest();
 con.open("GET",url,true);
 con.onreadystatechange=function()
 {
  if(con.readyState==4 && con.status==200)
  {
   temp = con.responseText.split(",");
   document.getElementById("hours").innerHTML=temp[0];
   document.getElementById("min").innerHTML=temp[1];
   document.getElementById("sec").innerHTML=temp[2];
   }
  }
 con.send(null);
 }

</script>
</head>
<body onload="setInterval('request_time()',1000)">
<div class="clock_container">
 <span id="hours" class="cw pr"></span>
 <span class="cw">:</span>
 <span id="min" class="cw pr"></span>
 <span class="cw">:</span>
 <span id="sec" class="cw"></span>
</div>
</body>
</html>
Then the second file is a PHP file.

get_time.php
PHP Code:

<?php
$date
=date("h");
$date.=",".date("i");
$date.=",".date("s");
echo 
$date;
?>
Put both files in the same directory and run the HTML file.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom errors with asp.net MS2003/IIS6 janetb ASP.NET 1 09-12-06 02:59 PM
Difference between the user control and Custom server controls bhar ASP.NET 0 07-22-06 05:42 AM
[FOR SALE:] Fully Featured Custom Forum Nefarious Dev General Advertisements 0 06-27-06 05:08 PM
Custom CMS for sale! icap General Advertisements 4 02-20-06 01:30 AM
Custom IE Toolbar Development for your company or Website Chadhaajay General Advertisements 0 10-28-05 01:01 AM


All times are GMT -5. The time now is 09:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.