View Full Version : Local Time

12-04-2005, 10:25 PM

Sorry for the question... I am quite new using this technology...My question is conserning the script you have with the local time... somewhere it says that works only "with SSI ot PHP"

I have tested saving the file as shtml and it works like a charm. But then i try to save it as asp file does not work... is there any way to include the shtml file in a asp file in order to present it properly in my site???

Sorry if my question is quite irrelevant

thank you

12-05-2005, 01:42 AM

The script as is requires that your page either by SSI (.shtml) or PHP (.php) enabled. ASP won't do, but only because I'm not familiar with the syntax needed to output the current date in ASP. If anyone knows how, I'm sure the script can easily be modified for ASP pages as well.

I'll do a search online as soon as I have the time.

12-05-2005, 07:44 AM
Hi all,

Has anyone use this script with asp page??. I would be very grateful if you could share this information.


12-06-2005, 08:37 AM
Ok, I did some research, and have modified the script to support ASP pages as well: http://www.dynamicdrive.com/dynamicindex6/localtime.htm Mainly, just replace the code of Step 1 with the new version, then use "server-asp" as the keyword to pass into showLocalTime() to indicate your page is ASP.

12-06-2005, 09:54 PM
ddadmin thank you very much for your response...but it seems that does not work...

it appears like this

Current Server Time:NaN:NaN:NaN AM (undefined)
Current LA Time:NaN:NaN:NaN AM (undefined)
Current New York Time:NaN:NaN:NaN AM (undefined)

the code i use is the following

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

var thisobj=this
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second

var thisobj=this
if (this.displayversion=="long")
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




Current Server Time:<span id="timecontainer"></span><br />
Current LA Time:<span id="timecontainer2"></span><br />
Current New York Time:<span id="timecontainer3"></span><br />

<script type="text/javascript">
new showLocalTime("timecontainer", "server-asp", 0, "short")
new showLocalTime("timecontainer2", "server-asp", -60, "short")
new showLocalTime("timecontainer3", "server-asp", 120, "short")



Ami doing something wrong???

12-07-2005, 01:15 AM
It looks right. Are you sure the page you're putting this script on is ASP enabled? Here's an example I uploaded onto a ASP host that shows the script working: http://d.1asphost.com/georgecc/time.asp

12-07-2005, 07:39 AM
quite strange....could u please upload here the script of the page you used in your above post???

I cant understand whats going on.... :confused:

12-07-2005, 07:45 AM
ok...i went to file---> view source...copy paste the code... and guess what...

it is playing like a charm....

Gracias....Gracias... Gracias :)

12-11-2005, 05:13 PM
well, I tested with Opera browser and plays well ... but with IE I realise now that it doesnt work at all... any idea why is this could happen???

Quite strange isn't it?

12-11-2005, 05:30 PM
well you can see it here... www.spinoza.gr ....go to the bottom of the page...if you have opera as i said before you will see that it plays

12-12-2005, 01:03 AM
Hmmm that is strange, especially considering the exact script runs fine on this asp page (http://d.1asphost.com/georgecc/time.asp) using IE. I'll try and update this thread if I spot the problem in the next few days, though ASP isn't my strong suit. heh

12-19-2005, 05:58 AM
Hi ddadmin,

could you tell me in which version of IE are u playing the above script???
I am using 6.0.... is it the same?

Thank you

12-21-2005, 01:04 PM
Yep, I'm using IE6 Win XP. Does the script on the page I posted display correctly for you?

12-22-2005, 10:50 AM
I am afraid not... does not work and i cant understand why... with the opera browser it works perfectly well but not with IE... :mad:

I have asked from my users to tell me if they see the local time (to test if it is my browser) but they cannot see it too...

I am really stumped with this situation :eek:

12-23-2005, 10:01 AM
Please post a URL to the problem page on your site then. It might have something to do with the ASP function I used to retrieve the current server time not being supported on your server, but then again, if that's the case, no browser should see the date.

12-23-2005, 01:07 PM
the url is


Please if you have Opera browser check it as well....you will see that with the Opera it works like a charm....

Thank you

01-28-2006, 01:40 PM
I'd like to add that the PHP function is not working either.

I know for a fact that I have a PHP enabled server, because I've run other PHP files without problem. I have a test page up at ...


At first I couldn't even get the line of text that says "Current Server Time: " to appear without IE reporting an error. Finally, I did a "View Source" on the php file on the server and located the line of code that was reporting the error. Oddly enough, it was the part of code in Step 1 for servers running SSI. Once I removed it though, the error reported by IE went away, the line of text that said "Current Server Time:" finally showed up, BUT the date and time would not display.

I'm stumped at this point and I've been trying for over an hour. Any help would be appreciated.


01-28-2006, 11:02 PM
BrightStarPro, the local time script on your page is incomplete. Just by viewing source, I see the line:

var servertimestring=(servermode=="server-php")? 'January 28, 2006 16:58:04'

That line definitely is mising a good chunk of code.

Please go back to the script page, (http://www.dynamicdrive.com/dynamicindex6/localtime.htm) and recopy the script. Make sure whatever editor you're using doesn't inadvertantly modify/remove parts of the script.

01-29-2006, 07:02 PM
BrightStarPro, the local time script on your page is incomplete. Just by viewing source, I see the line:

var servertimestring=(servermode=="server-php")? 'January 28, 2006 16:58:04'

That line definitely is mising a good chunk of code.

Please go back to the script page, (http://www.dynamicdrive.com/dynamicindex6/localtime.htm) and recopy the script. Make sure whatever editor you're using doesn't inadvertantly modify/remove parts of the script.

That's correct. I had to remove that huge chunk of code just to "some" of the script to work originally. I've restored all of the code and I'm getting the same problem I had before. If you do a view source, you'll see

var servertimestring=(servermode=="server-php")? 'January 29, 2006 12:59:53' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<br />
<b>Fatal error</b>: Call to undefined function: now() in <b>/export/home/bstarpro/public_html/rhs96/test.php</b> on line <b>18</b><br />

Note the Fatal Error on the last line. The original file is located at http://www.brightstarpro.com/rhs96/test.php
I've also made sure to establish "server-php" in Step 2 of the instructions, as seen below.

Current Server Time:<span id="timecontainer"></span>

<script type="text/javascript">
new showLocalTime("timecontainer", "server-php", 0, "short")

This one has me stumped, but I'm sure it's something I'm overlooking.

01-30-2006, 02:01 AM
The URL http://www.brightstarpro.com/rhs96/test.php contains a PHP error that's causing the page to load blank. From the source:

<b>Fatal error</b>: Call to undefined function: now() in <b>/export/home/bstarpro/public_html/rhs96/test.php</b> on line <b>18</b><br />

This might even explain why the local time script isn't working for you based on the above.