SimplePortal

Customization => Custom Coding => Topic started by: Costa on October 24, 2008, 05:00:31 PM

Title: What's the code for a watch
Post by: Costa on October 24, 2008, 05:00:31 PM
Hello folks

I would like to know wath's the code to add a watch (clock) in a block

Something like this

(http://img408.imageshack.us/img408/5006/imagemhw8.png)

* edited in paint   ;P

I want that watch "read" the time on Windows (not the time of the server)

Thanks for the people who help me  :D

Farewell
~[Costa]
Title: Re: What's the code for a watch
Post by: cme1st2302 on October 24, 2008, 08:49:01 PM
This (http://www.weberdev.com/get_example-4589.html) has some code that works.  Just make it an html block. I tested it and it looks good.

Chris
Title: Re: What's the code for a watch
Post by: Costa on October 25, 2008, 08:07:27 AM
Don't show the numbers...   :( why?
Title: Re: What's the code for a watch
Post by: ibm450 on October 25, 2008, 08:32:07 AM
works a treat, be better to display date also

cheers great mod
Title: Re: What's the code for a watch
Post by: cme1st2302 on October 25, 2008, 02:14:57 PM
To add the date replace the code with this

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<center><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simple Javascript Digital Clock</title>
<style type="text/css" media="all">
.frm {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #164BA0;
    background-color: #D1D1D1;
    border: 1px solid #83AAD3;
}
</style>

</head>

<body>

<FORM NAME = "clockForm">
  <INPUT TYPE="text" NAME = "clock" SIZE = "10" class="frm">
</FORM>

<SCRIPT LANGUAGE="JavaScript">
  <!--
 
  function display() {
    var Today = new Date();
    var hours = Today.getHours();
    var min = Today.getMinutes();
    var sec = Today.getSeconds();
    var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours);
    Time += ((min < 10) ? ":0" : ":") + min;
    Time += ((sec < 10) ? ":0" : ":") + sec;
    Time += (hours >= 12) ? " PM" : " AM";
    this.clockForm.clock.value = Time;
    setTimeout("display()",1000);
  }

  display();

  -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!--  Author: www.cgiscript.net  -->

<!-- Begin

// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}

// Join it all together
today =  days[now.getDay()] + "<br /> " +
         months[now.getMonth()] + " " +
         date + ", " +
         (fourdigits(now.getYear())) ;

// Print out the data.
document.write(today);

//  End -->
</script>


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

Chris
SimplePortal 2.3.8 © 2008-2024, SimplePortal