Results 1 to 9 of 9

Thread: Local Time Script - Time Format

  1. #1
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Cool Local Time Script - Time Format

    1) Script Title: Local Time Script

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

    3) Describe problem: I just first want to say how much I love this site. There are a MILLION free script/tutorial sites online but this is by far my favorite. The beauty of your site is that EVERYTHING actually works. I have yet to find a script that did not work here and that is very rare online!!!! Great work =)

    Okay, now my questions... is there any way I can change the time format for the Local Time Script? The site I'm working on is for a company in Quebec so... instead of 1:00 PM, it would be 13:00 // 10:00 PM would be 22:00 etc...

    Any chance I get get some help making this format change? Thanks in advance.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Correct me if I'm wrong. It looks like you are happy with the script, but would like the time displayed in 24 hour format, and sans AM/PM, right?

    If so, and this would apply to the only time that you wish displayed (I'm guessing here that you want only 24 hour format Quebec time), then the following modifications should suffice:

    Code:
    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="long")
    this.container.innerHTML=this.localtime.toLocaleString()
    else{
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=""
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }
    Untested, but should work out as I stipulate. If you want the flexibility to show multiple times in the same 24 hour format, this should still be fine. However if you also want to be able to display some times in 12 hour AM/PM format, more modification would be required.
    - 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:

    MizzBia (01-06-2009)

  4. #3
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    This worked PERFECTLY!!!! Thank you so much John, I really appreciate you taking the time to help me with this.

    Oh and... Happy New Year!!

  5. #4
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Local Time Script - Remove seconds

    Thnaks for that, I've managed to get the 24 hr format working and removed the AM/PM but can you tell me how I can remove the seconds?

    I basically want to to show HH:MM, is this possible?

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Just get rid of that part. Let's zoom in on the long highlighted line from my last post:

    Code:
    this.container.innerHTML=formatField(hour)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    To get rid of the seconds, remove the highlighted. To have only HH:MM make that line like so:

    Code:
    this.container.innerHTML=formatField(hour)+":"+formatField(minutes)
    Last edited by jscheuer1; 05-24-2011 at 06:47 PM. Reason: English Usage
    - John
    ________________________

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

  7. #6
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    Thanks for the quick response and solution!

    I did notice however that what should be 06:00 is displayed as 6:00 and this could be confusing if international visitors are not aware of the format. Is there any way to fix this issue?

    Thanks again
    Paul
    Last edited by i-conicdesign; 05-25-2011 at 05:29 AM.

  8. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Shouldn't do that. The format field function should add the 0 prefix. Be sure to use:

    Code:
    formatField(hour)
    as in my previous post, NOT (as in the original script):

    Code:
    formatField(hour, 1)
    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 05-25-2011 at 06:43 AM. Reason: Add: If you want more help . . .
    - John
    ________________________

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

  9. #8
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks again John,

    I'll have to until the morning to see if it's worked

  10. #9
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks John

    Worked perfectly with your instructions.

    Many Thanks

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
  •