Date Object
ScriptEase shines in its ability to work with dates and provides two different systems for working with them. One is the standard Date object of JavaScript and the other is part of the Clib object which implements powerful routines from C. Two methods, Date.fromSystem() and Date toSystem(), convert dates in the format of one system to the format of the other. The standard JavaScript Date object is described in this section.
To create a Date object which is set to the current date and time, use the new operator, as you would with any object.
var currentDate = new Date();
There are several ways to create a Date object which is set to a date and time. The following lines all demonstrate ways to get and set dates and times. See Date() for a summary.
var aDate = new Date(milliseconds);
var bDate = new Date(datestring);
var cDate = new Date(year, month, day);
var dDate = new Date(year, month, day, hour, minute, second, millisecond);
The first syntax returns a date and time represented by the number of milliseconds since midnight, January 1, 1970. This representation in milliseconds is a standard way of representing dates and times that makes it easy to calculate the amount of time between one date and another. Generally, you do not create dates in this way. Instead, you convert them to milliseconds format before doing calculations.
The second syntax accepts a string representing a date and optional time. The format of such a datestring is:
month day, year hours:minutes:seconds
For example, the following string:
"Friday 13, 1995 13:13:15"
specifies the date, Friday 13, 1995, and the time, one thirteen and 15 seconds p.m., which, expressed in 24 hour time, is 13:13 hours and 15 seconds. The time specification is optional and if included, the seconds specification is optional.
The third and fourth syntaxes are selfexplanatory. All parameters passed to them are integers.
•
year
If a year is in the twentieth century, the 1900s, you need only supply the final two digits. Otherwise four digits must be supplied.
•
month
A month is specified as a number from 0 to 11. January is 0, and December is 11.
•
day
A day of the month is specified as a number from 1 to 31. The first day of a month is 1 and the last is 28, 29, 30, or 31.
•
hour
An hour is specified as a number from 0 to 23. Midnight is 0, and 11 p.m. is 23.
•
minute
A minute is specified as a number from 0 to 59. The first minute of an hour is 0, and the last is 59.
•
second
A second is specified as a number from 0 to 59. The first second of a minute is 0, and the last is 59.
For example, the following line of code:
var aDate = new Date(1492, 9, 12)
creates a Date object containing the date, October 12, 1492.
ScriptEase has a rich and full set of methods to work with dates and times. A programmer has a very complete set of tools to use when including date and time routines in a script. The Clib object also has methods for working with date and times that extend the power of ScriptEase beyond standard JavaScript.
The following list of methods has brief descriptions of the methods of the Date object. Instance methods are shown with a period, ".", in the syntax: line. A specific instance of a variable should be put in front of the period to call a method. For example, the Date object aDate was created above, and, to call the Date getDate() method, the call would be: aDate.getDate(). Static methods have "Date." at their beginnings since these methods are called with literal calls, such as Date.parse(). These methods are part of the Date object itself instead of instances of the Date object.