Full text Date
You should be up to speed at this point with how to present an array of text strings. This script uses two. This time around we'll learn how to extract the text string we want from each array. But first, familiarize yourself with the script and its effect once again.
Here's the code we're worried about today:
Let me explain this first line because once you get this line down, the rest just fall into place:
var day = DaysofWeek[RightNow.getDay()]
What follows it the variable name of the first array, DaysofWeek. Now we know that this line will act upon the first array. That's the one that lists the days of the week. (no duh!).
The format is the same as one of the DaysofWeek array item. There are square brackets immediately following the array name and inside those brackets is the code that will return the day of the week: "RightNow.getDay()".
So what's going to happen is, the "RightNow.getDay()" will return a number, zero through 6, representing the day of the week. Let's say the number returned is 4. In the DaysofWeek array, 4 means Thursday. Thus, the variable day now represents "Thursday". When you call on the variable day, the text "Thursday" will be returned.
The next line of code:
var date = RightNow.getDate()
The next line follows the array format exactly except this time around we're looking for the month of the year
var Month = Months[RightNow.getMonth()]
Let's say it's May. "RightNow.getMonth()" would return the number 4. That's equal to the text string "May" in the Months array. Thus when you call on the variable name Month, you'll get the text string "May".
The last line of code might be new to you.
var Year = RightNow.getFullYear()
In the past, I've used the older getYear() method to extract the year from the Date() object. Well, that works, but it only returns a two-digit year and with Y2K looming, that's not such a good thing. This new method getFullYear() returns the full four digit year. You should start using it across the board when you want a year displayed.
OK! Now we have all the returns ready to go. We have the day in text, the number date, the month in text, and a four digit year. Now all we need to do is decide what two-letter extension should print after the day number. Of course it has to be the right two letters. You don't want your text to read Tuesday May 11rd, 1999.
That would be bad.
Next Time: Those Two Letters