TCH-Thomas Posted December 5, 2003 Posted December 5, 2003 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 Quote
curtis Posted December 5, 2003 Posted December 5, 2003 Thomas, Go here to get the edited code for your 24 hour time: http://www.cmg02.com/test1/thomastime.htm Quote
surefire Posted December 5, 2003 Posted December 5, 2003 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") ?> Quote
TCH-Thomas Posted December 5, 2003 Author Posted December 5, 2003 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 Quote
curtis Posted December 5, 2003 Posted December 5, 2003 Thomas, I removed the AM and PM. Try it again at the above url Quote
TCH-Thomas Posted December 5, 2003 Author Posted December 5, 2003 Works and looks great. Thank you Curtis. -Thomas Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.