HTML Goodies: Script Tip: Week 31
Building the Right Environment to Support AI, Machine Learning and Deep Learning
Never Trust a Tip Over 30!
Once again, we're working on a requested script here. A reader wanted to post a date that goes beyond the basic number returns. He wanted the date to display in text. I am the author of the script below. I wrote it to present the day and the month in text.
As an added bonus, the script will add the "th", "st", "nd", or "rd" depending on the day of the month. I also used a new method to extract a four, rather than a two, digit year. It's a bit long, but it works pretty well.
Here are the goods:
Let's start from the top. This script relies on two arrays. The first array lists the days of the week and the second array lists the months of the year. Here's the first array, the days of the week:
DaysofWeek = new Array()
Each array starts with a line that announces to the browser that an array is starting. That line looks like this:
DaysofWeek = new Array()
The format is similar to setting up a new Date(), which we'll actually do later. The line announces a new Array() and gives the array a name. In this case the name is DaysofWeek. I made the name up just like I would a variable name, because in reality it is a variable name. It's just that this variable has multiple values.
The getDay() method returns the day of the week only it returns that day as a numeric value, zero through 6 representing Sunday through Saturday. Now do you see the reason for the order of days? We've set up an array of days that is equal to the returns that getDay()will return. A little later we'll get into why this is important.
Now that you're somewhat familiar with the format of an array, let's take a look at the second one. This one deals with the months of the year:
Months = new Array()
The name of the array is Months and the months are arranged in order, zero through 11 because those are the numbers that are returned by using the getMonth()method.
OK, now you're up to speed with the concept and structure of an array. We can begin calling for the array index through the getDay() and getMonth()methods.
Next Week: Pulling Out Part of the Array
IT Solutions Builder TOP IT RESOURCES TO MOVE YOUR BUSINESS FORWARD
Which topic are you interested in?
What is your company size?
What is your job title?
What is your job function?
Searching our resource database to find your matches...