PDA

View Full Version : Local Time Script - NaN:NaN:NaN AM (undefined) Error



audibleprofits
08-31-2007, 09:25 PM
1) Script Title: Local Time Script

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

3) Describe problem:

I've installed this script on my site and the time shows up as
NaN:NaN:NaN AM (undefined)

Here is the link to the page.
http://www.musicindustryhost.com/test/test.php

Thank!

Dino

tech_support
09-01-2007, 02:59 AM
Works fine for me (FF & IE7)

audibleprofits
09-01-2007, 03:05 AM
Thanks for checking that out.
I just hired a programmer to fix it so it works now.

Not sure what he did but here is the code that is working now.



/***********************************************
* 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")? 'August 31, 2007 22:41:04' : (servermode=="server-ssi")? '<!--#config timefmt="&#37;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
}

jscheuer1
09-01-2007, 04:52 AM
Glad it is now working. Without going over the particulars of this case, this script can sometimes require customization due to the way that a particular server is configured vis a vis outputting times and/or dates.

The script was written assuming USA English formatting of times and dates on the server side.

audibleprofits
09-01-2007, 06:20 AM
Thanks John,

I think the problem was I repeated the same code in either when I create a new time zone.

span id="timebox4"

Or

new showLocalTime("timebox4", "server-ssi", 0, "short")




Thanks,

Dino

huangpower
11-24-2008, 05:03 PM
Got the same error message and i think someone mentioned the script was written for the English based site. I am running a site that is based on Chinese Big5, wondering if there is anywhere on the script I can modify for it to work.

only_you523
03-25-2009, 02:11 AM
i have same problem is :
New York: NaN:NaN:NaN AM (undefined)
what i can do to fix that ?

jscheuer1
03-25-2009, 03:28 AM
If this old thread doesn't resolve your issue(s), please start a new thread:

Warning: Please include a link to the DD script in question in your post. See this thread (http://www.dynamicdrive.com/forums/showthread.php?t=6) for the proper posting format when asking a question.