You can create a new instance of the Date object in three ways:
dateObj = new Date();
dateObj = new Date(dateVal);
dateObj = new Date(year, month, date{, hours{, minutes{, seconds{,ms}}}});
If you just use the constructor Date(), the instance of the Date object will be set to current date and time.
If you use Date(dateVal) and dateVal is an integer, dateVal represents the number of milliseconds since midnight January 1, 1970 Universal Coordinated Time. Negative numbers indicate dates prior to 1970. If dateVal is a string, dateVal is parsed according to the rules in the parse method (go to parse for more information)). See Date Object Overview for more information on timezones on Forsta Plus servers.
Here are two ways of getting an instance of the Date Object that is set to midnight 2000 (UTC):
d = new Date(946684800000);
d = new Date("Sat, 1 Jan 2000 00:00:00 UTC");
When you use Date(year,month,date{,hours{,minutes{,seconds{,ms}}}}), the first three arguments are required. year has to be the full year, for example 1984 (and not just 84). month is an integer between 0 and 11 (This means that January is 0, December is 11. This is similar to how we have seen that arrays are indexed, where 0 is the first element). date is an integer between 1 and 31.
The next arguments are optional (that's what the curly brackets indicate), but when one of them is included, all preceding arguments must be supplied. This means that if you specify seconds, it has to be preceded by hours and minutes. hour is an integer from 0 to 23 (midnight to 11pm). minutes and seconds are integers from 0 to 59 and milliseconds is an integer from 0 to 999. Here is an example:
d = new Date(2000,0,1,0,0,0,0);This may or may not be equal to the two examples above using the other constructors. It depends on the server settings on the Forsta Plus server. The two examples above both use UTC. With this last constructor, the time zone cannot be specified. The time zone of the Forsta Plus server will be used.
If an argument is greater than its range or is a negative number, other stored values are modified accordingly. So 150 seconds will be redefined as 2 minutes and 30 seconds. The 2 minutes will be added to the minutes value. If this exceeds 60 minutes, hours will be modified and so on.