Click to See Complete Forum and Search --> : Need fix please and addition if pos


pcbugfixer
06-20-2003, 07:21 PM
In the freebies, Clocks there is this,

Title: Current Date & Time (Long)
Details: 2.21 KB * Uploaded September 1 1997
Description: This is the somewhat longer way to put the current date & time on your page. It writes in a longer date and time format than the previous date & time script. The script is also longer....

Which is,

http://javascript.internet.com/clocks/date-time-long.html#source

I'm not good at Java :o and it took John W. (friend) to help me fix it and get it to work for Sydney, Australia EST.

You can take a look at http://www.pcbugfixer.com

Now remains the small problem in that it does not update the time on my site when you load it and remains static as at the time you loaded the page.

Then we thought of a button to update, but that trips the Counter on the page and that is not desirable.

Anyone got a simple solution please. ie. get the clock to update the time automatically, please.
:D

AdamBrill
06-20-2003, 07:29 PM
I would do something like this:<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function update_clock(){
var day="";
var month="";
var myweekday="";
var year="";
newdate = new Date();
mydate = new Date();
dston = new Date('April 4, 1999 2:59:59');
dstoff = new Date('october 31, 1999 2:59:59');
var myzone = newdate.getTimezoneOffset();
newtime=newdate.getTime();

var zone = 14; // references your time zone

if (newdate > dston && newdate < dstoff ) {
zonea = zone - 14 ;
dst = " Australian EST";
}
else {
zonea = zone ; dst = " Australian EST";
}
var newzone = (zonea*60*60*1000);
newtimea = newtime+(myzone*60*1000)-newzone;
mydate.setTime(newtimea);
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
myyear= mydate.getYear();
year = myyear;

if (year < 2000)
year = year + 1900;
myhours = mydate.getHours();
if (myhours >= 12) {
myhours = (myhours == 12) ? 12 : myhours - 12; mm = " PM";
}
else {
myhours = (myhours == 0) ? 12 : myhours; mm = " AM";
}
myminutes = mydate.getMinutes();
if (myminutes < 10){
mytime = ":0" + myminutes;
}
else {
mytime = ":" + myminutes;
};
arday = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ")
ardate = new Array("1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st","0th");
// rename locale as needed.

var time = ("In Sydney, Australia, it is: " + myhours + mytime+ mm + ", " + arday[myday] +", " + armonth[mymonth] +" "+ardate[myweekday] + ", " + year+", " + dst +".");
document.getElementById("clock").innerHTML=time;
setTimeout("update_clock()",1000);
}
//-->
</SCRIPT>
</head>

<body onload="update_clock();">

<div id="clock">

</div>
</body>
</html>

Charles
06-20-2003, 07:47 PM
We can shorten that up a bit:

<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;

Date.prototype.toUTCOffset = function (offset) {return new Date(this.getTime() + this.getTimezoneOffset() * 60000 + offset * Date.ONE_HOUR)}

Date.prototype.toTimeString = function () {return [['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()], ['', '1st,', '2nd,', '3rd,', '4th,', '5th,', '6th,', '7th,', '8th,', '9th,', '10th,', '11th,', '12th,', '13th,', '14th,', '15th,', '16th,', '17th,', '18th,', '19th,', '20th,', '21st,', '22nd,', '23rd,', '24th,', '25th,', '26th,', '27th,', '28th,', '29th,', '30th,', '31st,'][this.getDate()], this.getFullYear(), [this.getHours() < 13 ? this.getHours() : this.getHours() - 12, this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':'), (this.getHours() < 13 ? ' AM' : ' PM')].join(' ')}

document.write('<p id="time">+10 GMT ', new Date().toUTCOffset(10).toTimeString(), '</p>');

if (document.getElementById) setInterval("document.getElementById('time').replaceChild(document.createTextNode ('+10 GMT ' + new Date().toUTCOffset(10).toTimeString()), document.getElementById('time').firstChild)", 0.2 * Date.ONE_SECOND);

// -->
</script>

pcbugfixer
06-20-2003, 09:09 PM
Thanks "AdamBrill"
? why is it slow in loading
please ?

Also thanks "Charles"

like that short and sweet version, think I will use that on the other pages,

or modify yours for 1st page, but would like the "Sydney, Australia. ________________ Australian EST" on the same line.

I will try and do that myself (if I can)

:D

AdamBrill
06-20-2003, 10:59 PM
The reason it loads slow is becuase it writes it in onload. My guess is that Charles method loads faster, so I would suggest that you just use that one...

pcbugfixer
06-20-2003, 11:31 PM
Originally posted by AdamBrill The reason it loads slow is becuase it writes it in onload. My guess is that Charles method loads faster, so I would suggest that you just use that one...

The one that John had fixed up for me was this one - (edited version of original) (it did not update time - but loaded fast)

Where did you make the *change* - please?

<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var day="";
var month="";
var myweekday="";
var year="";
newdate = new Date();
mydate = new Date();
dston = new Date('April 4, 1999 2:59:59');
dstoff = new Date('october 31, 1999 2:59:59');
var myzone = newdate.getTimezoneOffset();
newtime=newdate.getTime();

var zone = 14; // references your time zone

if (newdate > dston && newdate < dstoff ) {
zonea = zone - 14 ;
dst = " Australian EST";
}
else {
zonea = zone ; dst = " Australian EST";
}
var newzone = (zonea*60*60*1000);
newtimea = newtime+(myzone*60*1000)-newzone;
mydate.setTime(newtimea);
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
myyear= mydate.getYear();
year = myyear;

if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
myhours = mydate.getHours();
if (myhours >= 12) {
myhours = (myhours == 12) ? 12 : myhours - 12; mm = " PM";
}
else {
myhours = (myhours == 0) ? 12 : myhours; mm = " AM";
}
myminutes = mydate.getMinutes();
if (myminutes < 10){
mytime = ":0" + myminutes;
}
else {
mytime = ":" + myminutes;
};
arday = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ")
ardate = new Array("1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st","0th");
// rename locale as needed.

var time = ("In Sydney, Australia, it is: " + myhours + mytime+ mm + ", " + arday[myday] +", " + armonth[mymonth] +" "+ardate[myweekday] + ", " + year+", " + dst +".");
document.write(time);
//-->
</SCRIPT>


<!-- Script Size: 2.21 KB -->

BTW, to you know why this thread is displaying 4 times the normal width? the others don't!
:confused:

pcbugfixer
07-30-2003, 10:05 AM
Thanks for all the help Folks.
Looking good. minor delay loading, but it works ?:D :cool:

pcbugfixer
08-01-2003, 12:07 AM
AdamBrill fixed the last problem - however now that it is August, the Month did not automatically roll over hence the site now is still in July with the wrong date.

Can someone help me and fix this please, or tell me which lines I need to change in the script.

Site now points to www.pcbugfixer.com.au (redirect .com to .com.au)

Charles
08-01-2003, 04:40 AM
That's odd. My version, above, is working just fine.

pcbugfixer
08-01-2003, 09:15 AM
Originally posted by Charles
That's odd. My version, above, is working just fine.

Thanks for the reply Charles,
I am using the one from AdamBrill, as it had the "In Sydney Australia.... etc, and the second counter is good but ??? why use it.
However, if I can incorporate yours into the existing, then by all means why not.
Java, as I said - good at some things - Java is not one of them.
So if you can help please, do so, thanks.

Edited: For some reason it decided to work - did nothin for 2 days and it kicked in as at the August 2nd.
Question is, what was wrong with the 1st of August.:confused:

Charles
08-01-2003, 11:45 AM
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;

Date.prototype.toUTCOffset = function (offset) {return new Date(this.getTime() + this.getTimezoneOffset() * 60000 + offset * Date.ONE_HOUR)}

Date.prototype.toTimeString = function () {return [['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()], ['', '1st,', '2nd,', '3rd,', '4th,', '5th,', '6th,', '7th,', '8th,', '9th,', '10th,', '11th,', '12th,', '13th,', '14th,', '15th,', '16th,', '17th,', '18th,', '19th,', '20th,', '21st,', '22nd,', '23rd,', '24th,', '25th,', '26th,', '27th,', '28th,', '29th,', '30th,', '31st,'][this.getDate()], this.getFullYear(), [this.getHours() < 13 ? this.getHours() : this.getHours() - 12, this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':'), (this.getHours() < 13 ? ' AM' : ' PM')].join(' ')}

document.write('<p id="time">In Sydney Australia.... etc ', new Date().toUTCOffset(10).toTimeString(), '</p>');

if (document.getElementById) setInterval("document.getElementById('time').replaceChild(document.createTextNode ('In Sydney Australia.... etc ' + new Date().toUTCOffset(10).toTimeString()), document.getElementById('time').firstChild)", 0.2 * Date.ONE_SECOND);

// -->
</script>