Jump to content

Recommended Posts

Posted

The following time and date script shows 12 hour clock (AM/PM), can i make it show 24 hours, like 13.00:05?

 

><HEAD>

<script LANGUAGE="javascript">
<!-- Original:  Craig Lumley -->
<!-- Web Site:  http://www.ws4all.co.uk -->

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

<!-- Begin
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function funClock() {
if (!document.layers && !document.all)
return;
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = ""+ hours + ":" + minutes + ":" + seconds + " " + dn + "";
if (document.layers) {
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
setTimeout("funClock()", 1000)
}
window.onload = funClock;
//  End -->
</script>
</HEAD>

and

<BODY>
<span id=clock style="position:relative;"></span>

 

-Thomas

Posted

I've heard that javascript grabs the time from the user's computer... which has some advantages and disadvantages.

 

If you wanted to do it server side and use the time on the server, you could do it like this

 

><?php echo date("H.i:s") ?>

Posted

Thanks Jack :( , but im not too good at php yet, so I go with Curtis thing this time.

Just one question... Is there a way I can get rid of the AM/PM thing. No need for it if it shows 24 hours time.

 

-Thomas

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...