Results 1 to 1 of 1

Thread: Help on editing the Local Time script, I want 0's displayed before the hour.

  1. #1
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help on editing the Local Time script, I want 0's displayed before the hour.

    1) Script Title:
    Local Time Script

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamicindex6/localtime.htm

    3) Describe problem:
    Okay, what I exactly want is the script to display zeros before the hour, unless it's two numbers, for example:
    01:00:00 AM
    03:00:00 PM
    11:00:00 AM
    Something like that, I know that its something to do with this:

    Code:
    function formatField(num, isHour){
    if (typeof isHour!="undefined"){ //if this is the hour field
    var hour=(num>12)? num-12 : num
    return (hour==0)? 12 : hour
    }
    return (num<=9)? "0"+num : num//if this is minute or sec field
    }
    but I have no idea what.

    Thanks!

    Edit:
    I think I got it! I messed around with the script a bit and I came up with this:

    Code:
    function formatField(num, isHour){
    if (typeof isHour!="undefined"){ //if this is the hour field
    var hour=(num>12)? num-12 : num
    if (hour.toString().length==1)
    hour="0"+hour
    return (hour==0)? 12 :hour
    }
    return (num<=9)? "0"+num : num//if this is minute or sec field
    }
    If it seems wrong, tell me though, but this is solved for now.
    Last edited by MartinD2K5; 11-02-2007 at 02:07 AM. Reason: Solved it, I think. :D

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
  •