HTML and CSS Reference
In-Depth Information
The following code for the showTime() function is similar:
function showTime(dateObj) {
thisSecond = dateObj.getSeconds();
thisMinute = dateObj.getMinutes();
thisHour = dateObj.getHours();
return thisHour + “:” + thisMinute + “:” + thisSecond;
}
The showTime() function extracts the hours, minutes, and seconds values from the
Date object, returning the text string
hour :minute:second
where hour is the value of the thisHour variable, minute is the value of the
thisMinute variable, and second is the value of the thisSecond variable.
You'll add both the showDate() and showTime() functions to an external JavaScript
file so that you can access them from any page of Hector's Web site.
To create the showDate() and showTime() functions:
1. Use your text editor to open the functxt.js file from the tutorial.11\tutorial folder
included with your Data Files. Enter your name and the date in the comment sec-
tion at the top of the file, and then save the file as functions.js in the same folder.
2. Below the comment section, insert the following two functions, as shown in
Figure 11-10:
function showDate(dateObj) {
thisDate = dateObj.getDate();
thisMonth = dateObj.getMonth()+1;
thisYear = dateObj.getFullYear();
return thisMonth + “/” + thisDate + “/” + thisYear;
}
function showtime(dateObj) {
thisSecond = dateObj.getSeconds();
thisMinute = dateObj.getMinutes();
thisHour = dateObj.getHours();
return thisHour + “:” + thisMinute + “:” + thisSecond;
}
Figure 11-10
inserting the showdate() and showtime() functions
function to for mat and
display the current date
function to for mat and
display the current time
3. Save your changes to the file.
Search WWH ::




Custom Search