Results 1 to 7 of 7

Thread: Local time script fails in Firefox2 ???

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

    Unhappy Local time script fails in Firefox2 ???

    Local Time script

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

    Having problems with this script displaying in FF2 winxp(sp2)

    When copy and pasting sample code into a testpage and running the code on a known ASP server it runsOK in IE 6/7, but comes up with NaN in Firefox.

    Can anyone else verify that the exact source code works for ASP in Firefox?
    I get the following output: Current Server Time:NaN:NaN:NaN AM (undefined)

    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

    Yes. I just tried it. I copied the the code as instructed on the demo page and uploaded it to a known asp server (not asp.net, as far as I know) and it worked fine in FF 2.0.0.4 under Windows XP Pro 5.12600 Service Pack 2 Build 2600:

    filename - local_time_test.asp
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    /***********************************************
    * Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for this script and 100s more.
    ***********************************************/
    
    var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]
    
    function showLocalTime(container, servermode, offsetMinutes, displayversion){
    if (!document.getElementById || !document.getElementById(container)) return
    this.container=document.getElementById(container)
    this.displayversion=displayversion
    var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
    this.localtime=this.serverdate=new Date(servertimestring)
    this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
    this.updateTime()
    this.updateContainer()
    }
    
    showLocalTime.prototype.updateTime=function(){
    var thisobj=this
    this.localtime.setSeconds(this.localtime.getSeconds()+1)
    setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
    }
    
    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 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
    }
    
    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
    }
    
    </script>
    </head>
    <body>
    Current Server Time:<span id="timecontainer"></span>
    
    <script type="text/javascript">
    new showLocalTime("timecontainer", "server-asp", 0, "short")
    </script>
    </body>
    </html>
    If this doesn't clear things up for you, a link to your demo that exhibits the problem may help.
    - John
    ________________________

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

  3. #3
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cheers, here's the link to my demo URL
    What have I done wrong?
    Thanks again.

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

    Looks to me like it is working (no longer showing NaN, except in FF), but with:

    Current Server Time:2:27:24 AM (Wed)

    at 10:27pm (Mon) EDT that's a bit off, even for nz (if that's New Zealand), where it is 2:27pm (Tue) at the moment.
    - John
    ________________________

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

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

    Ah, I see now, your server is giving the date in this format:

    d/m/y h:m:s a.m.

    The script expects (on many computers in many browsers, this actually can vary):

    m/d/y h:m:s AM

    So, I would try adding this red stuff to the script:

    Code:
    this.localtime=this.serverdate=new Date(servertimestring.toUpperCase().replace(/\./g,'').replace(/^(\d*\/)(\d*\/)/,'$2$1'))
    - John
    ________________________

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

  6. #6
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah the joys of non-US date formats!

    Hey thanks heaps man - this has been a periodic headache for the last year or so when I first started with this script.

    Works perfect in FF now, but would be good if you could check again to see it still displays OK? - NZ is GMT+12 (+/-1 daylight saving).

    Thanks so much!

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

    FF on my computer here on the East Coast of the US is now displaying the accurate time for NZ as the server time:

    Current Server Time:3:42:28 PM (Thurs)

    (11:42pm EDT Wed) here.

    (UTC/GMT is 03:42 on Thursday, July 05, 2007) Greenwich
    - 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
  •