Chapter 3 DynaScript Predefined Objects
The Date
object
has these methods:
Date.getDate( )
Returns the day of the month in local time.
Integer.
This example displays the numeric day of the month:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( myDate.getDate() );
-->
Date.getDay( )
Returns the day of the week in local time.
An integer between 0 and 6.
This example displays the day of the week, which in this case is 1 (Monday):
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "week day: " + myDate.getDay() );
-->
Date.getFullYear( )
Returns the year in local time.
An absolute number representing the full year.
This example displays the full year of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "year: " + myDate.getFullYear() );
-->
Date.getHours( )
Returns the hours value in local time.
Integer between 0 and 23.
This example displays the numeric value of the Date objects hour:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "hour: " + myDate.getHours() );
-->
Date.getMilliseconds( )
Returns the milliseconds value in local time.
Integer from 0 to 999.
This example displays the number of milliseconds in the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Milliseconds: " + myDate.getMilliseconds() );
-->
Date.getMinutes( )
Returns the minutes value in local time.
Integer between 0 and 59.
This example displays the number of minutes in the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Minutes: " + myDate.getMinutes() );
-->
Date.getMonth( )
Returns the month value in local time.
Integer between 0 and 11. 0 is equal to January.
This example displays the month value of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Month: " + myDate.getMonth() );
-->
Date.getSeconds( )
Returns the seconds value.
Integer between 0 and 59.
This example displays the seconds value of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Seconds: " + myDate.getSeconds() );
-->
Date.getTime( )
Returns the time value in local time. This value represents the number of milliseconds between the specified time and midnight, January 1, 1970. Negative numbers indicate dates prior to midnight, January 1, 1970.
Integer.
This example displays the number of milliseconds that have elapsed since January 1, 1970 and the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Time: " + myDate.getTime() );
-->
Date.getTimezoneOffset( )
Returns the difference in minutes, between the local time and the Universal Coordinated Time.
Integer.
This example displays the number of minutes between the local time and the Universal Coordinated Time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Time zone offset: " + myDate.getTimezoneOffset() );
-->
Date.getUTCDate( )
Returns the numeric date of the Date object, in Universal Coordinated Time.
Integer between 1 and 31 that represents the date value in the Date object.
This example displays the numeric date of the date object in Universal Coordinated Time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
myUTCDate = myDate.getUTCDate();
document.WriteLn( "UTC date: " + myUTCDate );
-->
Date.getUTCDay( )
Returns the day of the week from the Date object, in Universal Coordinated Time.
Integer between 0 and 6 representing the day of the week.
This example displays the day of the week in UTC time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC date: " + myDate.getUTCDay() );
-->
Date.getUTCFullYear( )
Returns the full year from the Date object, in Universal Coordinated Time.
Integer.
This example displays the full year in UTC time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC full year: " + myDate.getUTCFullYear() );
-->
Date.getUTCHours( )
Returns the hours from the Date object, in Universal Coordinated Time.
Integer 0 to 23.
This example returns the hours in UTC time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC hours: " + myDate.getUTCHours() );
-->
Date.getUTCMilliseconds( )
Returns the milliseconds value in a Date object using Universal Coordinated Time.
Integer.
This example displays the number of milliseconds being held in the Date object in UTC time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC milliseconds: " + myDate.getUTCMilliseconds() );
-->
Date.getUTCMinutes( )
Returns the minutes value in a Date object, using Universal Coordinated Time.
Integer between 0 and 59.
This example displays the number of minutes being held in the Date object in UTC time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC minutes: " + myDate.getUTCMinutes() );
-->
Date.getUTCMonth( )
Returns the month value in a Date object, using Universal Coordinated Time.
Integer between 0 and 11.
This example displays the UTC month of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC month: " + myDate.getUTCMonth() );
-->
Date.getUTCSeconds( )
Returns the seconds value in a Date object, using Universal Coordinated Time.
Integer between 0 and 59.
This example displays the number of seconds (in UTC time) in the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC seconds: " + myDate.getUTCSeconds() );
-->
Date.getYear( )
Returns the year value in a Date object in
local time. Use the getFullYear
method instead,
to avoid Y2K problems.
Integer.
This example displays the year of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Year: " + myDate.getYear() );
-->
Date.parse( string )
Parses a string containing a date and returns the number of milliseconds between the date and midnight of January 1, 1970. The string may be in the following formats:
Use the parse method with the built-in Date object as shown in this example. The parse method does not work with instances of the Date object.
Integer (milliseconds).
This example returns the number of milliseconds between the date string and January 1, 1970:
<!--SCRIPT
dateString = "March 11, 1996"
document.WriteLn( Date.parse(dateString) );
-->
Date.setDate( numDate )
Sets the numeric day of the month of the Date object. numDate is a numeric value equal to the numeric date. If a value is greater than its range, the other values will be modified accordingly. For example, if the current date was January 3 and setDate was set to 33, the month would change to February and the date would be set to 2.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the numeric date of the Date object to the 23rd:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Date: " + myDate.getDate() );
myDate.setDate( "23" );
document.WriteLn( "Date: " + myDate.getDate() );
-->
Date.setFullYear( numYear [, numMonth, [numDate]] )
Sets the year value in the Date object. The range of years supported is approximately 285616 years on either side of 1970. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the year of the Date object to 1999:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Year: " + myDate.getFullYear() );
myDate.setFullYear( "99" );
document.WriteLn( "Year: " + myDate.getFullYear() );
-->
Date.setHours( numHours [, numMin, [numSec, [numMilli]]] )
Sets the hours value in the Date object using local time. If a value is greater than its range, the value will be modified accordingly. For example, the numHours value of 30 would actually be equal to 6:00:00 (a day plus 6 hours). The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the time of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Hours: " + myDate.getHours() );
myDate.setHours( "12", "15", "01" );
document.WriteLn( "Hours: " + myDate.getHours() );
-->
Date.setMilliseconds( numMilli )
Sets the milliseconds value in the Date object. numMilli is the numeric value equal to the millisecond value you wish to set. If the value is greater than 999, the number of seconds is increased as required. For example, 1020 milliseconds would be equal to one second and 21 milliseconds.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the number of milliseconds in the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Hours: " + myDate.getMilliseconds() );
myDate.setMilliseconds( "89" );
document.WriteLn( "Hours: " + myDate.getMilliseconds() );
-->
Date.setMinutes( numMin [, numSec, numMilli] )
Sets the minutes value in the Date object. If a value is greater than its range, the value will be modified accordingly. For example, the value of 80 minutes would actually be equal to 1:20:00. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the value of the minutes in the Date object. Because the number of minutes is larger than 59, the and the hour value will be incremented by one (to 9), and the minute value is changed accordingly.
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old Minutes: " + myDate.getMinutes() );
myDate.setMinutes( "89" );
document.WriteLn( "New hours: " + myDate.getHours() );
document.WriteLn( "New minutes: " + myDate.getMinutes() );
-->
The output from this example is:
Old Minutes: 30
New hours: 9
New minutes: 29
Date.setMonth( numMonth [, dateVal] )
Sets the month value for the Date object. January is equal to 0. If the value of a parameter exceeds its range, other parameters will be changed accordingly. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the month value of the Date object to March:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old month: " + myDate.getMonth() );
myDate.setMonth( "02" );
document.WriteLn( "New month: " + myDate.getMonth() );
-->
Date.setSeconds( numSec [, numMilli] )
Sets the seconds value in the Date object using local time. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the value of the seconds in the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setSeconds( "58" );
document.WriteLn( "Seconds: " + myDate.getSeconds() );
-->
Date.setTime( numMilli )
Sets the date and time value in the Date object. numMilli is an integer that represents the number of milliseconds that have elapsed since midnight, January 1, 1970 GMT. A negative number indicates a date earlier than January 1, 1970. PowerDynamo supports a range between -2147483649 and 2147483647. To set dates that are beyond this range, use a floating point.
Using setTime
to
set the date and time of a Date object is time zone independent.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example sets the date and time of a date
object with the setTime
method:
<!--SCRIPT
myDate = new Date( );
myDate.setTime( "5324654" );
document.WriteLn( "Year: " + myDate.getUTCFullYear() );
document.WriteLn( "Month: " + myDate.getUTCMonth() );
document.WriteLn( "Date: " + myDate.getUTCDate() );
document.WriteLn( "Hours: " + myDate.getUTCHours() );
document.WriteLn( "Minutes: " + myDate.getUTCMinutes() );
-->
The output from this example is:
Year: 1970
Month: 0
Date: 1
Hours: 1
Minutes: 28
Date.setUTCDate( numDate )
Sets the numeric date in the Date object using Universal Coordinated Time. numDate represents the date that is to be set.
If the value of a parameter exceeds its range, other parameters will be changed accordingly. For example, if the current date was January 12 and SetUTCDate(33) was given, the new month and date would be February 2.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the date of the Date object. Because the new date value exceeds the number of days in the month of February, the month value is incremented by one, and the date is changed accordingly:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old date: " + myDate.getUTCDate() );
document.WriteLn( "Old month: " + myDate.getUTCMonth() );
myDate.setUTCDate( "45" );
document.WriteLn( "New date: " + myDate.getUTCDate() );
document.WriteLn( "New month: " + myDate.getUTCMonth() );
-->
This example displays this output:
Old date: 11
Old month: 1
New date: 17
New month: 2
Date.setUTCFullYear( numYear [, numMonth, [numDate]] )
Sets the value of the year in the Date object using Universal Coordinated Time. The range of years supported is approximately 285616 years on either side of 1970. The parameters are
numDate
parameter
is specified, this parameter must also be set.If the value of a parameter exceeds its range,
other parameters are changed accordingly. For example if the current
date value was January 1, 1983 and the numDate
parameter
given is 32, the date changes to February 1, 1983.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the year of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCFullYear( "78" );
document.WriteLn( "New date: " + myDate.getUTCFullYear() );
-->
Date.setUTCHours( numHours [, numMin, [numSec, [numMilli]]] )
Sets the hours value in the Date object using Universal Coordinated Time. If a value is greater than its range, the value will be modified accordingly. For example, the numHours value of 30 would actually be equal to 6:00:00 (a day plus six hours). The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the hours value of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCHours( "9" );
document.WriteLn( "New hour: " + myDate.getUTCHours() );
-->
Date.setUTCMilliseconds( numMilli )
Sets the milliseconds value for the Date object. If the number of milliseconds is greater than 999 or a negative number, the stored number of seconds reflects this accordingly. For example, 1020 milliseconds is equal to one second and 21 milliseconds.
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the milliseconds value of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMilliseconds( "12" );
document.WriteLn( "New milliseconds: " + myDate.getUTCMilliseconds() );
-->
Date.setUTCMinutes( numMin [numSec, numMilli] )
Sets the minutes value in the Date object using Universal Coordinated Time. If a value is greater than its range, the value is modified accordingly. For example, the value of 80 minutes would actually be equal to 1:20:00. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the minute value of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMinutes( "45" );
document.WriteLn( "New minutes: " + myDate.getUTCMinutes() );
-->
Date.setUTCMonth( numMonth [, dateVal] )
Sets the month value for the Date object. January is equal to 0. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the month value of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMonth( "6" );
document.WriteLn( "New month: " + myDate.getUTCMonth() );
-->
Date.setUTCSeconds( numSec [, numMilli] )
Sets the seconds value in the Date object using Universal Coordinated Time. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:
Integer. The number of milliseconds since midnight, January 1, 1970.
This example changes the second value of the Date object and displays the new value:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCSeconds( "00" );
document.WriteLn( "New seconds: " + myDate.getUTCSeconds() );
-->
Date.setYear( numYear )
Sets the year value in the Date object. This method is currently maintained only for backward compatibility. Use the setFullYear method instead.
Integer. The number of milliseconds since midnight, January 1, 1970.
Date.toGMTString( )
Returns a date as a string in Greenwich Mean Time. This method is currently supported only for backward compatibility. Use the toUTCString instead.
String.
Date.toLocaleString( )
Returns a date as a string using the current locale.
String. The format of this string changes depending on the locale. For example, the date January 10, 1998 is represented by:
This example displays the value of the Date object in local time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toLocaleString() );
-->
The output from this example is:
Wed, 11 Feb 1998 08:30:11
Date.toString( )
Returns the date as a string in a convenient, readable format in local time.
String.
This example displays the value of the Date object in local time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toString() );
-->
The output from this example is:
Wed, 11 Feb 1998 08:30:11
Date.toUTCString( )
Returns a date as a string in Universal Coordinated Time.
String.
This example displays the value of the Date object in Universal Coordinated Time:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toUTCString() );
-->
The output from this example is:
Wed, 11 Feb 1998 13:30:11 UTC
Date.valueOf( )
Returns the time value in local time. This value represents the number of milliseconds between the specified time and midnight, January 1, 1970. Negative numbers indicate dates prior to midnight, January 1, 1970.
Integer.
This example displays the number of milliseconds that have elapsed since January 1, 1970 and the value of the Date object:
<!--SCRIPT
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.valueOf() );
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |