The Date object has two static methods. They are called static because they are called without creating an instance of the Date object. They are parse and UTC. The other methods are invoked as methods of a created instance of the Date object. In code below dateObj is an instance of a Date object.
See Date Object Overview for more information on timezones on Forsta Plus servers.
Static Methods
The Date object has two static methods. They are called static because they are called without creating an instance of the Date object. They are parse and UTC.
parse
parseParses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
Date.parse(dateVal)
dateVal is a string containing a date.
The parse method returns an integer value representing the number of milliseconds between midnight, January 1, 1970 and the date supplied in dateVal.
The parse method is a static method of the Date object. Because it is a static method, it is invoked as shown in the following example, rather than invoked as a method of a created Date object.
Date.parse("January 1, 2000 00:00 AM")The following rules govern what the parse method can successfully parse:
- Short dates can use either a "/" or "-" date separator, but must follow the month/day/year format, for example "7/20/96".
- Long dates of the form "July 10 1995" can be given with the year, month, and day in any order, and the year in 2-digit or 4-digit form. If you use the 2-digit form, the year must be greater than or equal to 70.
- Any text inside parentheses is treated as a comment. These parentheses may be nested.
- Both commas and spaces are treated as delimiters. Multiple delimiters are permitted.
- Month and day names must have two or more characters. Two character names that are not unique are resolved as the last match. For example, "Ju" is resolved as July, not June.
- The stated day of the week is ignored if it is incorrect given the remainder of the supplied date. For example, "Tuesday November 9 1996" is accepted and parsed even though that date actually falls on a Friday. The resulting Date object contains "Friday November 9 1996".
- All standard time zones, as well as Universal Coordinated Time (UTC) and Greenwich Mean Time (GMT), are accepted time zones.
- Hours, minutes, and seconds are separated by colons, although all need not be specified. "10:", "10:11", and "10:11:12" are all valid.
- If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
- A string containing an invalid date is an error. For example, a string containing two years or two months is an error.
UTC
UTC returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the supplied date.
Date.UTC(year, month, day{, hours{, minutes{, seconds{,ms}}}})The arguments are equal to those of the Date(year,month,day{,hours{,minutes{,seconds{,ms}}}}) constructor (go to Constructors for more information).
If a particular argument's value is outside of its range, then the other arguments' values are modified accordingly. For example, if 150 seconds is specified, the survey engine redefines that number as two minutes and 30 seconds.
The difference between the UTC method and the corresponding Date object constructor is that the UTC method assumes UTC, and the Date object constructor assumes local time. (Local time when doing server side scripting will be the time zone of the Forsta Plus servers, not the time zone of the client (the PC of the respondent)).
The UTC method is a static method. Therefore, a Date object does not have to be created before it can be used.
Date.UTC(2000,0,1,0,0,0,0)