Jinidoc Posted January 22, 2011 Share Posted January 22, 2011 Error "Current Server Time:NaN:NaN:NaN AM (undefined)" *****Code****** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <head> <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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Current Server Time:<span id="timecontainer"></span> <script type="text/javascript"> new showLocalTime("timecontainer", "server-ssi", 0, "short") </script> </body> </html> Please help. Reply Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/ Share on other sites More sharing options...
.josh Posted January 22, 2011 Share Posted January 22, 2011 Try changing new showLocalTime("timecontainer", "server-ssi", 0, "short") to new showLocalTime("timecontainer", "server-php", 0, "short") Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1163607 Share on other sites More sharing options...
Jinidoc Posted January 23, 2011 Author Share Posted January 23, 2011 Hi Crayon, Thanks for helping me,tried changing the below code but still the issue remain the same Regards Jini Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164067 Share on other sites More sharing options...
.josh Posted January 23, 2011 Share Posted January 23, 2011 okay well then where are you trying to run that script? That script expects to be run from either a php or ssi server. Are you trying to run it locally on your computer with no server setup? Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164069 Share on other sites More sharing options...
Jinidoc Posted January 23, 2011 Author Share Posted January 23, 2011 I am Running WAMSERVER,I have name this file as servertime.php.tried to execute this on webpage I am below error "Current Server Time:NaN:NaN:NaN AM (undefined)". Tried to run the same on IE but no go. I had taken the code from below link and tried on WAMP Server. http://www.dynamicdrive.com/dynamicindex6/localtime.htm Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164073 Share on other sites More sharing options...
.josh Posted January 23, 2011 Share Posted January 23, 2011 and you are sure that your "WAMSERVER" is setup correctly and correctly running php? Make a page with the following code <?php echo "test"; ?> does that show a page with "test"? Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164128 Share on other sites More sharing options...
Jinidoc Posted January 24, 2011 Author Share Posted January 24, 2011 Yes, I get the display as Test Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164491 Share on other sites More sharing options...
.josh Posted January 24, 2011 Share Posted January 24, 2011 hmm...maybe your server isn't setup to recognize short tags... okay try also changing this line 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() %>' to this: var servertimestring=(servermode=="server-php")? '<?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() %>' Quote Link to comment https://forums.phpfreaks.com/topic/225307-unable-to-display-running-time-on-webpage/#findComment-1164503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.