Results 1 to 10 of 10

Thread: Dual Clock

  1. #1
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Dual Clock

    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.")

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    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>
    The dispTime() function should return the dates. To execute:
    Code:
    <script type="text/javascript">
    alert(dispTime());
    </script>
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    Sunset (09-29-2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey on mine it says its AM and not PM. is that on anyone elses?

  5. #4
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question

    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?

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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">&nbsp;</div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Sunset (09-29-2008)

  8. #6
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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!

  9. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    John, why do you do functions like this?:
    Code:
    function time12_24(){
    Mburt told me that the new way to do them is like this:
    Code:
    var time12_24 = function(){
    I'm just curious..
    Jeremy | jfein.net

  10. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Nile View Post
    John, why do you do functions like this?:
    Code:
    function time12_24(){
    Mburt told me that the new way to do them is like this:
    Code:
    var time12_24 = function(){
    I'm just curious..
    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:

    Code:
    var name = function(){}
    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.

    When code is well written, using:

    Code:
    function name(){}
    can distinguish a function as being in the global scope.

    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

  11. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I asked mburt why he said its newer, idk you'll have to ask him.
    Jeremy | jfein.net

  12. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Nile View Post
    I asked mburt why he said its newer, idk you'll have to ask him.
    As far as I know, it's not new, just different and has implications as I stated when used within a limited scope, but not in the global scope (like the function of mine that you were asking about). I'll ask him if it ever comes up in a thread we both participate in.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •