Javascript

Home / projects / code / Javascript

Some simple Javascript examples.

Timestamp Code

This is the code for the script that handles the date at the bottom of the pages for this website.


<script language="JavaScript">
<!--this runs the date on the page neat eh?//

function makeMonthArray() {
        this.length=11;
        this[0] = "Jan.", this[1] = "Feb."; this[2] = "March";
        this[3] = "April", this[4] = "May"; this[5] = "June";
        this[6] = "July", this[7] = "Aug."; this[8] = "Sept.";
        this[9] = "Oct.", this[10] = "Nov."; this[11] = "Dec.";
        return(this);
}

function makeDayArray() {
        this.length=6;
        this[0] = "Sunday", this[1] = "Monday"; this[2] = "Tuesday";
        this[3] = "Wednesday", this[4] = "Thursday"; this[5] = "Friday";
        this[6] = "Saturday";
        return(this);
}

function writeDate() {
        attdate = new Date();
        monthName = new makeMonthArray();
        dayName = new makeDayArray();
        day = attdate.getDay();
        date = attdate.getDate();
        month = attdate.getMonth();
        year = 2000 + (attdate.getYear() - 100);
                        
        dateStr  = dayName[day];
        dateStr += ", ";
        dateStr += monthName[month];
        dateStr += " ";
        dateStr += date;
        dateStr += ", ";
        dateStr += year;
        document.write(dateStr);
        if ((attdate.getDay()) == 5) {document.write(" <FONT COLOR=red>yay it's Friday!</FONT>");}
        if ((attdate.getDay()) == 6) {document.write(" <FONT COLOR=red>Saturday is ok I guess...</FONT>");}
        if ((attdate.getDay()) == 0) {document.write(" <FONT COLOR=red>back to work soon :(</FONT>");}
}

//thats all there is to it-->
</script>

Just include the above after the header and before the body, then stick the below in the page somewhere.


<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">writeDate()</SCRIPT>