Cuc Tu
07-20-2009, 08:27 PM
I just don't use it enough.
I'm trying to show the current ISO week number on my HTML page.
The page is really simple with just a few paragraphs and a table.
Under body in paragraph tag, I insert:
<script type="text/javascript">document.write(date());</script>
Nothing shows there, so i try some other code I found:
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<center>" + lmonth + " ");
document.write(date + ", " + year + "</center>");
// End -->
</script>
That shows the date. I still need the week number and found this good looking code:
<script type="text/javascript">
/**
* Get the ISO week date week number
*/
Date.prototype.getWeek = function () {
// Create a copy of this date object
var target = new Date(this.valueOf());
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (this.getDay() + 6) % 7;
// Set the target to the thursday of this week so the
// target date is in the right year
target.setDate(target.getDate() - dayNr + 3);
// ISO 8601 states that week 1 is the week
// with january 4th in it
var jan4 = new Date(target.getFullYear(), 0, 4);
// Number of days between target date and january 4th
var dayDiff = (target - jan4) / 86400000;
// Calculate week number: Week 1 (january 4th) plus the
// number of weeks between target date and january 4th
var weekNr = 1 + Math.ceil(dayDiff / 7);
return weekNr;
}
</script>
But it does not show the week number anywhere, so I add the following line before the end script tag:
document.write("Week" + weekNr);
But it does not write anything, not even the word "Week"
So I start looking at the code that actually wrote the date. It has these elements, which I add:
<!-- Begin
// End -->
But nothing shows.
So now I realize that I don't know what I'm doing.
Also, I tried the code here, but I have the same sort of result, mostly not knowing how to use it?
http://www.meanfreepath.com/support/getting_iso_week.html
I also tried the code in the head with the document.write function in the body.
?
I'm trying to show the current ISO week number on my HTML page.
The page is really simple with just a few paragraphs and a table.
Under body in paragraph tag, I insert:
<script type="text/javascript">document.write(date());</script>
Nothing shows there, so i try some other code I found:
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<center>" + lmonth + " ");
document.write(date + ", " + year + "</center>");
// End -->
</script>
That shows the date. I still need the week number and found this good looking code:
<script type="text/javascript">
/**
* Get the ISO week date week number
*/
Date.prototype.getWeek = function () {
// Create a copy of this date object
var target = new Date(this.valueOf());
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (this.getDay() + 6) % 7;
// Set the target to the thursday of this week so the
// target date is in the right year
target.setDate(target.getDate() - dayNr + 3);
// ISO 8601 states that week 1 is the week
// with january 4th in it
var jan4 = new Date(target.getFullYear(), 0, 4);
// Number of days between target date and january 4th
var dayDiff = (target - jan4) / 86400000;
// Calculate week number: Week 1 (january 4th) plus the
// number of weeks between target date and january 4th
var weekNr = 1 + Math.ceil(dayDiff / 7);
return weekNr;
}
</script>
But it does not show the week number anywhere, so I add the following line before the end script tag:
document.write("Week" + weekNr);
But it does not write anything, not even the word "Week"
So I start looking at the code that actually wrote the date. It has these elements, which I add:
<!-- Begin
// End -->
But nothing shows.
So now I realize that I don't know what I'm doing.
Also, I tried the code here, but I have the same sort of result, mostly not knowing how to use it?
http://www.meanfreepath.com/support/getting_iso_week.html
I also tried the code in the head with the document.write function in the body.
?