Is there a way to put a dual display on a web page of both local standard time and also in military time?
(i.e. "The current time is 1:45 pm / 1345.")
Is there a way to put a dual display on a web page of both local standard time and also in military time?
(i.e. "The current time is 1:45 pm / 1345.")
Here:
The dispTime() function should return the dates. To execute:Code:<script type="text/javascript"> var dispTime = function(){ var timeUpd = new Date(); var localTime = timeUpd.getHours(); if(localTime > 12){ localTime -= 12; } var ext; if(localTime > 11){ ext = "PM"; } else { ext="AM"; } localTime = localTime+":"+timeUpd.getMinutes()+" "+ext; var armTime = timeUpd.getHours()+":"+timeUpd.getMinutes()+" "+ext; return localTime+"/"+armTime; } </script>
Code:<script type="text/javascript"> alert(dispTime()); </script>
Jeremy | jfein.net
Sunset (09-29-2008)
hey on mine it says its AM and not PM. is that on anyone elses?
Thanks, but mine is also showing AM (when it should currently be PM). It's also showing AM on the military half of the display (when military time does not display AM or PM).
Also, is there a way to have the time display on the website itself, rather than as a popup?
I have a question, you mean the user's local time or the local time of the website? Both Nile's version and the one below are the user's local time:
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> #timeDisplay { font: normal 90% sans-serif; } #timeDisplay b { color: #f00; } </style> <script type="text/javascript"> function time12_24(){ var el = document.getElementById('timeDisplay'), d = new Date(), h = d.getHours(), m = d.getMinutes(), b = document.createElement('b'); m = m < 10? '0' + m : m; while (el.lastChild) el.removeChild(el.lastChild); b.appendChild(document.createTextNode((h%12 || 12) + ':' + m + (h < 12 ? ' am' : ' pm') + ' / ' + (h < 10? '0' + h : h) + m + ' hrs')); el.appendChild(document.createTextNode('The current time is - ')); el.appendChild(b); }; window.onload = function(){ time12_24(); setInterval(time12_24, 1000); }; </script> </head> <body> <div id="timeDisplay"> </div> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Sunset (09-29-2008)
Yes! Thank you, jscheuer1 - This is exactly what I was looking for. The visitor's local time in both 12-hour and 24 hour formats together.
I appreciate the responses and the help!
John, why do you do functions like this?:
Mburt told me that the new way to do them is like this:Code:function time12_24(){
I'm just curious..Code:var time12_24 = function(){
Jeremy | jfein.net
I'm not aware of any advantage in writing a function definition in that manner, unless it is part of another function and is going to be used in certain ways within the scope of that function.
Can you point out any case where there is an advantage in using the:
syntax for functions defined in the global scope? Perhaps you could link to a post in which Mburt explains this, or to some other resource that does.Code:var name = function(){}
When code is well written, using:
can distinguish a function as being in the global scope.Code:function name(){}
However, I have never been one to keep up on all the very latest practices - many of which are just a matter of opinion, and/or extremely browser specific as far as their value goes (meaning it may work cross browser, yet have no real advantage except in a specific browser). It is enough for me that code be valid and work. I also do like code to be, if not as efficient as possible, at least not so poorly constructed that it causes problems due to execution speed. I'm always willing to learn, though.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks