Results 1 to 4 of 4

Thread: Change display of date for Local Time Script

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

    Default Change display of date for Local Time Script

    1) Script Title: Local Time script

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

    3) Describe problem:
    Hello,

    the script is great, many thanks. I am using displayversion=="short" top show the date but i want to change i.e. 19 October 2011 to 19/10/2011

    im using this:
    Code:
    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="short")
    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+")"
    this.container.innerHTML=formatField(hour)+":"+formatField(minutes)
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }
    how can i do this?

    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

    How about we create our own displayversion and call it "min":

    Code:
    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="long")
    this.container.innerHTML=this.localtime.toLocaleString()
    else if(this.displayversion=="min"){
    this.container.innerHTML=this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' + this.localtime.getFullYear();
    }else{
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=(hour>=12)? "PM" : "AM"
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }
    Then you can do like:

    Code:
    <script type="text/javascript">
    new showLocalTime("timecontainer", "server-ssi", 0, "min")
    </script>
    If you still want the 9:34:32 AM part:

    Code:
    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="long")
    this.container.innerHTML=this.localtime.toLocaleString()
    else if(this.displayversion=="min"){
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=(hour>=12)? "PM" : "AM"
    this.container.innerHTML = formatField(hour, 1 )+ ':' + formatField(minutes) + ':' + formatField(seconds) + ' ' +
    ampm + ' ' + this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' + this.localtime.getFullYear();
    }else{
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=(hour>=12)? "PM" : "AM"
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }
    - 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:

    Foundas (10-19-2011)

  4. #3
    Join Date
    Nov 2007
    Posts
    63
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    many thanks for that....i am actually using your modification from another post, where i show the date in 24h and removed the seconds too...moved date in front of time and now i have 19/10/2011 18:00


    thank you!!!!!

  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

    For anyone interested, that would be:

    Code:
    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="long")
    this.container.innerHTML=this.localtime.toLocaleString()
    else if(this.displayversion=="min"){
    var hour=this.localtime.getHours();
    var minutes=this.localtime.getMinutes();
    this.container.innerHTML = this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' +
    this.localtime.getFullYear() + ' ' + formatField(hour)+ ':' + formatField(minutes);
    }else{
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=(hour>=12)? "PM" : "AM"
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }
    - 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
  •