The GET command is used to retrieve a part of the current date or time. The information is constructed from the visitor's computer settings.
To properly use this feature, a new variable has to be set using a special value.
I used "thedate" as the variable name for the example. You can change it to any other name you like.
The value new Date( ) tells the browser that this variable is going to contain a specified date and/or time. It is a base setting or ground. Once that is in place, the other elements can be built on top of it.
Here is an example that shows how to print out today's date:
The result ~ Today's date is : 19 / 1 / 119
Here is a break down of what is happening in the example :
- a variable called thedate is being used to create a date and/or time value.
- Print out the day, month and year.
How about an example that shows a message relating to the time of day?
The result ~ It is morning
Here is a break down of what is happening in the example:
- a variable is set to collect a date/time.
- a variable is set to get the HOUR (0 to 23) of the day.
- IF the hour is less than 12 (noon), then write "Morning", else continue on.
- IF the hour passed 12 and is less than 17 (4 o'clock), then write "Afternoon", else continue on.
- IF the hour passed the first 2 tests, the hour must be greater than 17, so write "Evening".