Results 1 to 6 of 6

Thread: Local Time - date display?

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

    Default Local Time - date display?

    Hi all, can somebody help me to display the date as well as the time in "Local Time script"

    http://www.dynamicdrive.com/dynamicindex6/localtime.htm

    The script shows: // Current New York Time: 19:54:44 (Tues) //

    How can I display this for example: 19:54:44 (29-11-2005 - Tues)

    with SSI ot PHP no mather my server support them both.


    Thank you!

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Sure. To get the script to display the current full date as well, just replace the old function:


    Code:
     showLocalTime.prototype.updateContainer=function(){ 
    "
    "
    }
    inside the script with the below version instead:

    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=(hour>=12)? "PM" : "AM"
    var currentdate=this.localtime.getDate()+"-"+(this.localtime.getMonth()+1)+"-"+this.localtime.getFullYear()
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+currentdate+" - "+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }

  3. #3
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thank you very much.

    Thank you for your help Admin, yes it works with span id, div id... but I can't get it to work inside a text field value. Say for example I'm updating some info in my page and every time I click save, I want to have a text field like:
    <input type="text" id="timecontainer" name="timecontainer" value='local time here'> so i can see when I have updated this info.

    If you have this: <input type="text" id="timecontainer" name="timecontainer" value=' '> you will see the time inside the text field, but it is not in the ( value=' ' ) so when you click SAVE the text field is empty.

    - How can I display inside the ( value=' ' )?


    Many thanks!

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Well, to get the script to display itself inside a <input> field, simply replace all occurences of "innerHTML" inside the script with "value" instead (there should be two of them). Then create a form such as:

    Code:
     <form> 
    <input type="text" id="timecontainer" />
    </form>
    where "timecontainer" is the ID of the form field to show the date. I'm not sure if this answers your question, as what you're asking seems to be more specific.

  5. #5
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your response Admin, but this isn't working, this is what i said above that it show the time inside the field, but is not in the (value='is empty') section...

  6. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmmm if you see the local time in the <input> field, it means its "value" attribute has been changed. It should also mean that when you submit the form, the local time gets submitted as well. I don't see why this wouldn't be the case unless there is something malfunctioning with your form submit script?

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
  •