JavaScript Source Code 3000: Calculators: Day of Week
Day of Week
Calculate what day of the week a given date was. It works for leap yYears and also tells you whether the date is in the past future or today.
Choose Date
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
Choose Month
January
February
March
April
May
June
July
August
September
October
November
December
Year
JavaScript Source Code 3000: Calculators: Day of Week
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL DAY OF WEEK:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Peter Bonnett (PeterBonnett@hotmail.com) -->
<!-- Web Site: http://uk.geocities.com/peterbonnett -->
<! >
<! >
<!-- Begin
var D = "0";
var M = "0";
var Y = "0";
var C = "0";
var B = "0";
var A = "0";
var Day = "0";
var Ending = "0";
var Dayow = new Array();
Dayow[-6] = "Monday";
Dayow[-5] = "Tuesday";
Dayow[-4] = "Wednesday";
Dayow[-3] = "Thursday";
Dayow[-2] = "Friday";
Dayow[-1] = "Saturday";
Dayow[0] = "Sunday";
Dayow[1] = "Monday";
Dayow[2] = "Tuesday";
Dayow[3] = "Wednesday";
Dayow[4] = "Thursday";
Dayow[5] = "Friday";
Dayow[6] = "Saturday";
var mnth = new Array();
mnth[0] = "January";
mnth[1] = "February";
mnth[2] = "March";
mnth[3] = "April";
mnth[4] = "May";
mnth[5] = "June";
mnth[6] = "July";
mnth[7] = "August";
mnth[8] = "September";
mnth[9] = "October";
mnth[10] = "November";
mnth[11] = "December";
function calcul() {
if (document.calculate.mnth.options.value == 0 || document.calculate.day.options.value == 0 || document.calculate.year.value.length == 0) {
alert('Please complete all options');
}
else if (document.calculate.mnth.options.value == 2 && document.calculate.day.options.value == 30 || document.calculate.mnth.options.value == 2 && document.calculate.day.options.value == 31) {
alert('That Month does not have '+ document.calculate.day.options.value +' days');
}
else if (document.calculate.mnth.options.value == 4 && document.calculate.day.options.value == 31) {
alert('That month does not have '+ document.calculate.day.options.value +' days');
}
else if (document.calculate.mnth.options.value == 6 && document.calculate.day.options.value == 31) {
alert('That month does not have '+ document.calculate.day.options.value +' days');
}
else if (document.calculate.mnth.options.value == 9 && document.calculate.day.options.value == 31) {
alert('That month does not have '+ document.calculate.day.options.value +' days');
}
else if (document.calculate.mnth.options.value == 11 && document.calculate.day.options.value == 31) {
alert('That month does not have '+ document.calculate.day.options.value +' days');
}
else {
calcul2();
}
}
function calcul2() {
D = document.calculate.day.options.value;
M = document.calculate.mnth.options.value;
Y = document.calculate.year.value;
if (M < 3) {
M = ((M / 1) + 12);
Y = (Y - 1);
date2();
}
else {
date2();
}
}
function date2() {
C = (parseInt(Y / 100));
B = (Y - (100 * C));
A = ((parseInt((2.6 * M) - 5.39)) + (parseInt(B / 4)) + (parseInt(C / 4)) + (D / 1) + B - (2 * C));
Day = (A - (7 * (parseInt(A / 7))));
Leap = ((Y / 4) - (parseInt(Y / 4)));
if (Leap != 0 && M >= 3 && A < 0) {
Day =- -Day;
daycalcu();
}
else if (Leap == 0 && M < 3 && A < 0) {
Day = (Day - 2);
daycalcu();
}
else {
daycalcu();
}
}
function daycalcu() {
if (document.calculate.mnth.options.value == 2 && document.calculate.day.options.value == 29 && Leap == 0) {
alert('February does not have '+ document.calculate.day.options.value +' days in '+ document.calculate.year.value +'');
}
else {
appear();
}
}
function appear() {
if (document.calculate.day.options.value == 1 || document.calculate.day.options.value == 21 || document.calculate.day.options.value == 31) {
Ending = "st";
appear2();
}
else if (document.calculate.day.options.value == 2 || document.calculate.day.options.value == 22) {
Ending = "nd";
appear2();
}
else if (document.calculate.day.options.value == 3 || document.calculate.day.options.value == 23) {
Ending = "rd";
appear2();
}
else {
Ending ="th";
appear2();
}
}
function appear2() {
test = new Date();
gdate = test.getDate();
gyear = test.getFullYear();
gmonth = test.getMonth();
E = (gmonth + 1);
D = document.calculate.day.options.value;
M = document.calculate.mnth.options.value;
Y = document.calculate.year.value;
F = (M - 1);
if (gyear == Y && gdate == D && E == M) {
alert('The '+ document.calculate.day.options.value + Ending +' of '+ mnth[F] +' '+ document.calculate.year.value +' is a '+ Dayow[Day] +'');
}
else if (gyear < Y || gyear == Y && E < M || gyear == Y && E == M && gdate < D) {
alert('The '+ document.calculate.day.options.value + Ending +' of '+ mnth[F] +' '+ document.calculate.year.value +' will be a '+ Dayow[Day] +'');
}
else if (gyear > Y || gyear == Y && E > M || gyear == Y && E == M && gdate > D) {
alert('The '+ document.calculate.day.options.value + Ending +' of '+ mnth[F] +' '+ document.calculate.year.value +' was a '+ Dayow[Day] +'');
}
else {
alert('The '+ document.calculate.day.options.value + Ending +' of '+ mnth[F] +' '+ document.calculate.year.value +' was a '+ Dayow[Day] +'');
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<form name="calculate">
<select name="day">
<option>Choose Date
<option value="1">1st
<option value="2">2nd
<option value="3">3rd
<option value="4">4th
<option value="5">5th
<option value="6">6th
<option value="7">7th
<option value="8">8th
<option value="9">9th
<option value="10">10th
<option value="11">11th
<option value="12">12th
<option value="13">13th
<option value="14">14th
<option value="15">15th
<option value="16">16th
<option value="17">17th
<option value="18">18th
<option value="19">19th
<option value="20">20th
<option value="21">21st
<option value="22">22nd
<option value="23">23rd
<option value="24">24th
<option value="25">25th
<option value="26">26th
<option value="27">27th
<option value="28">28th
<option value="29">29th
<option value="30">30th
<option value="31">31st
</select>
<select name="mnth">
<option>Choose Month
<option value="1">January
<option value="2">February
<option value="3">March
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">August
<option value="9">September
<option value="10">October
<option value="11">November
<option value="12">December
</select>
<input type=text name="year" size=4 maxlength=4> Year
<br>
<input type=button value="Calculate" onclick="calcul()">
</form>
<!-- Script Size: 6.84 KB -->
Wyszukiwarka
Podobne podstrony:
day of week redirectionM A Foster@Ler 03@The Day of the KleshSimak, Cliffard D Day of Trucefunction mcal day of yearFirst Day of ForeverDzień szakala (The Day of the Jackal)function mcal day of yearCarnivale s01e11 The Day of the DeadWilhelm, Kate The Happiest Day of Her LifeDay of Reckoningday of month redirectionfunction mcal day of yearChristie Kelley A Week of Pleasure (html)System Of A Down Lonely Dayfunction mcal week of yearwięcej podobnych podstron