Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 Universal Clock
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

GauravBhabu
Advanced Member

4288 Posts

Posted - 23 July 2001 :  13:39:33  Show Profile
This will display real clock time ticking second by second.

*********Step 1

Add the following code to inc_top just above the </script> tag

 
function displaydatetime() {
if (!document.layers && !document.all)
return;
var today;
var timeLocal;
var timeUTC;
today = new Date();
timeLocal = today.toLocaleString() + " " + "Local"; //Convert to current locale.
timeUTC = today.toUTCString(); //Convert to UTC string. //(IE ONLY)
if (document.layers) {
document.layers.clockLocal.document.write(timeLocal);
document.layers.clockLocal.document.close();
document.layers.clockUTC.document.write(timeUTC);
document.layers.clockUTC.document.close();
}
else if (document.all) {
clockLocal.innerHTML = timeLocal;
clockUTC.innerHTML = timeUTC;
}
setTimeout("displaydatetime()", 500)
}
window.onload = displaydatetime;


*******Step 2

Search for this line in inc_top.asp

<b><% '##=strForumTitle %></b>

just after this add the following lines


<font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>" color="<% =strDefaultFontColor%>">
<span id=clockLocal style="position:relative;"></span><br>
<span id=clockUTC style="position:relative;"></span>
</font>



Demo:just a beginning...
Demo:forumSquare
Demo:Universal Clock
gauravbhabu

There is only one miracle...That is LIFE!

Edited by - gauravbhabu on 23 July 2001 13:42:55

Edited by - gauravbhabu on 23 July 2001 21:21:38

Edited by - gauravbhabu on 23 July 2001 21:23:45

Edited by - gauravbhabu on 26 July 2001 19:56:17

stuF
Average Member

United Kingdom
561 Posts

Posted - 23 July 2001 :  15:10:35  Show Profile  Visit stuF's Homepage
do we have to change anything to make the time local?
i mean to make it GMT?
or will it do this automatically?

Go to Top of Page

Aznknight
Senior Member

USA
1373 Posts

Posted - 23 July 2001 :  16:26:25  Show Profile  Send Aznknight an AOL message  Send Aznknight an ICQ Message
nope it runs on the client's browser so you don't have to do anything for your user local time.

nice code gauravBhabu .

- Alan
www.iamviet.com
www.calvsa.net
Snitz Resource
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 23 July 2001 :  19:48:53  Show Profile
Thanks Aznknight !


gauravbhabu

There is only one miracle...That is LIFE!
Go to Top of Page

@tomic
Senior Member

USA
1790 Posts

Posted - 23 July 2001 :  21:45:07  Show Profile  Visit @tomic's Homepage  Send @tomic an ICQ Message
What is the UTC time anyway?

@tomic

Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 23 July 2001 :  22:22:29  Show Profile
quote:

What is the UTC time anyway?

@tomic





Definition from MSDN

UTC time (Universal Time Coordinate or Greenwich Mean Time). The current UTC time is derived from the current local time and the time zone setting in the operating system of the computer...



gauravbhabu

There is only one miracle...That is LIFE!

Edited by - gauravbhabu on 23 July 2001 22:30:33
Go to Top of Page

stinhoutx
Starting Member

12 Posts

Posted - 23 July 2001 :  22:34:04  Show Profile

I have read that there is a shortcoming in JavaScript's implementation where it has trouble handling this? (As far as with reference to UTC time) Ex. CST is -6, but CDT is -5. Either way you will get the correct local time, but the UTC may be off.


** This link doesn't speak to my JavaScript reference, but it gives related information:
http://www.codeproject.com/datetime/dstbugs.asp

Edited by - stinhoutx on 23 July 2001 22:42:12
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 23 July 2001 :  22:39:01  Show Profile
quote:

Does it work for Daylight Savings?
I have read that there is a shortcoming in JavaScript's implementation where it has trouble handling this? I will look it up if there is enough interest...





There is a method to look up fpr daylight savings. I am doing research to implement it. If you find it post it.

gauravbhabu

There is only one miracle...That is LIFE!
Go to Top of Page

stinhoutx
Starting Member

12 Posts

Posted - 23 July 2001 :  22:51:41  Show Profile

Here is a link to a JavaScript that does the work:http://developer.irt.org/script/281.htm

This looks like it will handle the basic change for the four US time zones. But, parts of Indiana, Arizona, Alaska, and Hawaii do not participate. Time period is between 1st Sunday in April through last Sunday in October.

Anyway, the effort to implement is definitely commended!! Maybe an addition to the profile to determine if they participate in DST in their location. Or, mirror the locale implementation and set to a best guess based on the result of your JavaScript calculation and let the user modify if necessary. Wow, what a job.

Hope this helped.

Go to Top of Page

bonkers
Junior Member

United Kingdom
122 Posts

Posted - 25 July 2001 :  16:12:25  Show Profile  Visit bonkers's Homepage
quote:

*********Step 1

Add the following code to inc_top just above the </script> tag

 
function displaydatetime() {
if (!document.layers && !document.all)
return;
var today;
var timeLocal;
var timeUTC;
today = new Date();
timeLocal = today.toLocaleString() + " " + "Local"; //Convert to current locale.
timeUTC = today.toUTCString(); //Convert to UTC string.
if (document.layers) {
document.layers.clockLocal.document.write(timeLocal);
document.layers.clockLocal.document.close();
document.layers.clockUTC.document.write(timeUTC);
document.layers.clockUTC.document.close();
}
else if (document.all) {
clockLocal.innerHTML = timeLocal;
clockUTC.innerHTML = timeUTC;
}
setTimeout("displaydatetime()", 500)
}
window.onload = displaydatetime;

I added this and got error "missing" }
*******Step 2

Search for this line in inc_top.asp

<b><% '##=strForumTitle %></b>

just after this add the following lines
Does this HAVE to go here

<font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>" color="<% =strDefaultFontColor%>">
<span id=clockLocal style="position:relative;"></span><br>
<span id=clockUTC style="position:relative;"></span>
</font>


gauravbhabu


I have tried to add this to Tschives portal but cannot get it to work. I added the missing } but it still did`nt display the time.
Any help would be appreciated.

bonkers
bonkers Test Portal
http://user.7host.com/bonkers/
Go to Top of Page

Aznknight
Senior Member

USA
1373 Posts

Posted - 25 July 2001 :  18:14:17  Show Profile  Send Aznknight an AOL message  Send Aznknight an ICQ Message
quote:

I added this and got error "missing" }



I don't see why you would need an extra closing parenthesi/curly bracket.

the window.onload = displaydatetime; is actually outside of the displaydatetime function which is how it's suppose to be. There's already two opening curly brackets and two corresponding closing brackets. added another one would make it an odd number.

quote:

Does this HAVE to go here



No you can put the spans where you want the clocked to be displayed. Under the title seemed like a good place. again great code gauravBhabu

- Alan
www.iamviet.com
www.calvsa.net
Snitz Resource
Go to Top of Page

Dan Martin
Average Member

USA
528 Posts

Posted - 25 July 2001 :  18:47:54  Show Profile  Visit Dan Martin's Homepage  Send Dan Martin an AOL message  Send Dan Martin an ICQ Message  Send Dan Martin a Yahoo! Message
quote:

There is a method to look up fpr daylight savings. I am doing research to implement it. If you find it post it.

gauravbhabu

There is only one miracle...That is LIFE!



Not sure why offsetting is necessary, since your mod runs client side. But since it's being looked into:

There is only one way I've found to offset times that works for everyone, everywhere. Here's the code I use, which passes the current server time to the client to create an offset. This gives you the relative time, which should work even if their computer is on Mars' time.

This goes in the <head>

<script Language=JavaScript>
var yearDiff, monthDiff, dayDiff, hourDiff, minuteDiff, secondDiff, bufferedHourDiff, AMPM;

function setOffSet(serverYear, serverMonth, serverDate, serverHours, serverMinutes, serverSeconds){
var clientTime = new Date();
var serverTime = new Date(serverYear, serverMonth, serverDate, serverHours, serverMinutes, serverSeconds);
yearDiff = clientTime.getFullYear() - serverTime.getFullYear();
monthDiff = clientTime.getMonth() - serverTime.getMonth();
dayDiff = clientTime.getDate() - serverTime.getDate();
hourDiff = clientTime.getHours() - serverTime.getHours();
minuteDiff = clientTime.getMinutes() - serverTime.getMinutes();
secondDiff = clientTime.getSeconds() - serverTime.getSeconds();
bufferedHourDiff = hourDiff;
if (minuteDiff >= 40) {
bufferedHourDiff = bufferedHourDiff + 1;
} else {
if (minuteDiff <= -40) {
bufferedHourDiff = bufferedHourDiff - 1;
}
}
}

function getYearDiff(){
return yearDiff;
}
function getMonthDiff(){
return monthDiff;
}
function getDayDiff(){
return dayDiff;
}
function getHourDiff(){
return hourDiff;
}
function getMinuteDiff(){
return minuteDiff;
}
function getBufferedHourDiff(){
return bufferedHourDiff;
}

function getOffSetHour(thisHour) {
AMPM=true;
var newHour = thisHour + bufferedHourDiff;
if (newHour > 12) {
newHour = newHour - 12;
AMPM = false;
} else {
if (newHour < 1) {
if (newHour < 0) {
AMPM = false
}
newHour = newHour + 12;
}
}
return newHour;
}

function getAMPM(thisAMPM) {
if (AMPM != true) {
if (thisAMPM == "PM") {
thisAMPM = "AM";
} else {
thisAMPM = "PM"
}
}
return thisAMPM;
}
setOffSet(<%=Year(Now()) & "," & Month(Now()) & "," & Day(Now()) & "," & Hour(Now()) & "," & Minute(Now()) & "," & Second(Now())%>);
</script>

This goes anywhere you want an offset time:

<script language=javascript>
document.write(getOffSetHour(<%=thisHour%>) + ":<%=thisMinute%> " + getAMPM("<%=thisAMPM%>"));
</script>


Where thisHour, thisMinute, thisAMPM are some hour, minute, and AM/PM values are broken out from the time you are trying to display (listed in the server's time zone). Important to notice from the javascript, this code can be used to adjust for more than just hours....but I've yet to implement it to that extent.

I've had alot of luck with that code, and you could probably port it to your needs.

-Dan

Edited by - Dan Martin on 25 July 2001 18:53:23
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 25 July 2001 :  19:25:38  Show Profile
The offset time is just to display. The client time will be correct always. But to display the corrcet offset we need to take into account the DaylightSavings period depending on the timezone or location.

Share A Square at forumSquare


gauravbhabu

There is only one miracle...That is LIFE!
Go to Top of Page

@tomic
Senior Member

USA
1790 Posts

Posted - 25 July 2001 :  20:40:55  Show Profile  Visit @tomic's Homepage  Send @tomic an ICQ Message
I just wanted to mention that mac users have a problem with this clock.
After the clock loads, everything after the clock code, and the clock, disappears!

I take that back. This happens when Netscape is the browser and it happens to PC and Mac users alike.

@tomic



Edited by - @tomic on 25 July 2001 21:43:15
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 25 July 2001 :  22:01:27  Show Profile
Thanks for reporting. I will have it fixed

Share A Square at forumSquare


gauravbhabu

There is only one miracle...That is LIFE!
Go to Top of Page

Guru
Starting Member

32 Posts

Posted - 26 July 2001 :  09:01:45  Show Profile
quote:

I just wanted to mention that mac users have a problem with this clock.
After the clock loads, everything after the clock code, and the clock, disappears!

I take that back. This happens when Netscape is the browser and it happens to PC and Mac users alike.


Please keep us informed bout this issue...

Another question:
How much work is it to tweak the code that you can alter it in an real-time count-down ticker?
Like to use it for upcoming events: Still 2 days 3 hours 12 minutes and 15 seconds till [whatever] or something like this....

Nice work btw

Cheers, Guru

Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000 Version 3.4.07