Results 1 to 7 of 7

Thread: How can I Create a display digital clock with GMT + 8 to display for all??

  1. #1
    Join Date
    Feb 2008
    Posts
    83
    Thanks
    26
    Thanked 1 Time in 1 Post

    Question How can I Create a display digital clock with GMT + 8 to display for all??

    I like this format but I scoured the web and found no solution for this. The closest I found was this confusing and containing extra times I don't want page: http://www.developer.com/lang/article.php/640011

    And this one seems like it may work but there are NO instructions about what to do with the code or how to input the HTML!
    http://www.crays.com/jsc/jsC4Udate.htm#DateTime

    I just want a text only 12 hour format wherever viewed: GMT +8 (Manila time)
    Such as: 12:22am

    That's it!

    Thanks in advance.

  2. #2
    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

    You're in luck! There is no DST in Manila. That makes it so much easier:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Manila Time</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <span>Time in Manila - <span id="manilatime">&nbsp;</span></span>
    <script type="text/javascript" defer>
    ;(function(){
    var getManilaTime = function(){
    var d = new Date(), h, m, s, ampm;
    d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
    d.setHours(d.getHours() + 8);
    h = d.getHours();
    m = d.getMinutes();
    s = d.getSeconds();
    ampm = h > 11? 'pm' : 'am';
    h = h%12 || 12;
    document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ':' + s + ampm;
    }
    getManilaTime();
    setInterval(getManilaTime, 1000);
    })();
    </script>
    </body>
    </html>
    - John
    ________________________

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

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

    johnwboyd (08-12-2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    83
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Thanks a lot

    I removed the seconds and got the font clean for my layout: www.NegrosChristianChurch.info

  5. #4
    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 think you are going to want to add one little bit to the code:

    Code:
    ;(function(){
    var getManilaTime = function(){
    var d = new Date(), h, m, ampm;
    d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
    d.setHours(d.getHours() + 8);
    h = d.getHours();
    m = d.getMinutes();
    m = m.toString(10).length < 2? '0' + m : m;
    ampm = h > 11? 'pm' : 'am';
    h = h%12 || 12;
    document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ampm;
    }
    getManilaTime();
    setInterval(getManilaTime, 1000);
    })();
    That will make minute values less than 10 pad with a zero:

    00
    01
    02
    03

    etc.
    - John
    ________________________

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

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

    johnwboyd (08-12-2008)

  7. #5
    Join Date
    Feb 2008
    Posts
    83
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default

    Now we're talking! : ) You're the best you noted that fix before I even replied.

  8. #6
    Join Date
    Feb 2008
    Posts
    83
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default one last question

    What if I want to add a space in between the time and pm or am?

  9. #7
    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

    Code:
    document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ' ' + ampm;
    - John
    ________________________

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

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

    johnwboyd (08-13-2008)

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
  •