Dates
Programming dates always raises special issues.
Javascript has some mechanisms for dates:
- Javascript has a
Date object.
- It has methods for manipulating dates.
Here is an example form that compares two dates.
In its source code, observe:
- Object instantiation with the new method (no parentheses!)
- getDate(), getMonth(), and other date methods.
- Conversion from milliseconds (returned by getTime()) to days.
- Remedies for Javascript date implementation strangenesses are sometimes necessary
(see below).
Javascript dates have some problems:
- Y2K (sort of) -- years are expressed as years since 1900
- so the year 2000 appears as 100
- year comparisons will not actually fail
- but years in the current millennium are expressed as 2-digit numbers
- Day-of-the-month is 1-31...
- But month is 0 (Jan.) through 11 (Dec.)
- Hours and minutes also count from 0.
The Date object methods used in this example are:
getDate() -- Gets the day of the month for a specified date.
getMonth() -- Gets the month for a specified date.
getYear() -- Gets the year for a specified date.
setYear() -- Sets the year for a specified date.
Lab
Your task:
- Copy the example form and edit it as follows.
- Reject the shipping date if it precedes or equals the order date.
Solution
Don't peek unless you're stuck!