To be able to use the Date class we need to define objects of that type. To do this we use a command very similar to that which we used to define arrays.
The way to define an object as a date is like this:
For example, to set our date object to 15th April 2006 you can specify the following immediately after the above declaration:
One of the most useful areas where using the date class is useful is where you need to either compare two dates or to change a date or time by a specified amount. For example let's say that we want to compare today's date with the 15th April 2006. Is today before or after that date? To do this we need to add the following code to what we have already defined above:
As well as comparing dates we can also easily manipulate dates. For example say that we need to work with the date exactly one week in the future All we need to do with a date object is to add 7 to the days portion of the date like this:
|All times are GMT +5.5. The time now is 02:53.|