Author |
Topic |
GauravBhabu
Advanced Member
4288 Posts |
Posted - 23 July 2001 : 13:39:33
|
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
|
do we have to change anything to make the time local? i mean to make it GMT? or will it do this automatically?
|
|
|
Aznknight
Senior Member
USA
1373 Posts |
Posted - 23 July 2001 : 16:26:25
|
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 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 23 July 2001 : 19:48:53
|
Thanks Aznknight !
gauravbhabu
There is only one miracle...That is LIFE! |
|
|
@tomic
Senior Member
USA
1790 Posts |
Posted - 23 July 2001 : 21:45:07
|
What is the UTC time anyway?
@tomic
|
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 23 July 2001 : 22:22:29
|
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 |
|
|
stinhoutx
Starting Member
12 Posts |
Posted - 23 July 2001 : 22:34:04
|
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 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 23 July 2001 : 22:39:01
|
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! |
|
|
stinhoutx
Starting Member
12 Posts |
Posted - 23 July 2001 : 22:51:41
|
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.
|
|
|
bonkers
Junior Member
United Kingdom
122 Posts |
Posted - 25 July 2001 : 16:12:25
|
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/ |
|
|
Aznknight
Senior Member
USA
1373 Posts |
Posted - 25 July 2001 : 18:14:17
|
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 |
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 25 July 2001 : 18:47:54
|
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 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 25 July 2001 : 19:25:38
|
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! |
|
|
@tomic
Senior Member
USA
1790 Posts |
Posted - 25 July 2001 : 20:40:55
|
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 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 25 July 2001 : 22:01:27
|
Thanks for reporting. I will have it fixed
Share A Square at forumSquare
gauravbhabu
There is only one miracle...That is LIFE! |
|
|
Guru
Starting Member
32 Posts |
Posted - 26 July 2001 : 09:01:45
|
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
|
|
|
Topic |
|