Welcome to the second part of an eight-part series on building a web page calendar. In this part of the series, I will explain the function that is used to create the current calendar. When the Show Current Month's Calendar button is clicked, it should call a function that will display the calendar of the current month. We need to modify it; the showCal() function we saw in the previous part has only one line. We will change this function and use it as the showCurrentMonth() function.
Creating a Web Page Calendar - The Date Object (Page 2 of 4 )
Here I will give you a summary of JavaScript's Date object, which is a top-level object.
You can use the Date object and its methods to work with dates and times in your applications. The Date object has a large number of methods for setting, getting, and manipulating dates. It does not have any properties.
JavaScript stores dates as the number of milliseconds since January 1, 1970, 00:00:00.
The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.
To create a Date object:
dateObjectName = new Date([parameters])
where dateObjectName is the name of the Date object being created; it can be a new object or a property of an existing object.
The parameters in the preceding syntax can be nothing, a string or a set of integer values. The description is as follows:
Nothing: creates today's date and time. For example, today = new Date().
A string representing a date in the following form: "Month day, year hours:minutes:seconds." For example, Xmas95 = new Date("December 25, 1995 13:30:00"). If you omit hours, minutes, or seconds, the value will be set to zero.
A set of integer values for year, month, and day. For example, Xmas95 = new Date(1995,11,25). A set of values for year, month, day, hour, minute, and seconds. For example, Xmas95 = new Date(1995,11,25,9,30,0).
JavaScript depends on platform-specific date facilities and behavior; the behavior of the Date object varies from platform to platform.
Methods of the Date Object
The Date object methods for handling dates and times fall into these broad categories:
"set" methods, for setting date and time values in Date objects.
"get" methods, for getting date and time values from Date objects.
"to" methods, for returning string values from Date objects.
parse and UTC methods, for parsing Date strings.
With the "get" and "set" methods, you can get and set seconds, minutes, hours, day of the month, day of the week, months, and years separately. There is a getDay method that returns the day of the week, but no corresponding setDay method, because the day of the week is set automatically. These methods use integers to represent these values as follows: