Constructor
new Date(numOrYearOrBasicStringopt, monthIndexopt, dayopt, hoursopt, minutesopt, secondsopt, millisecondsopt)
If given no parameters, the Date will be created from the current system time and date, which
includes the host machine's local timezone. The Date constructor must be called with new, and
it is an error to call the Date function directly.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
numOrYearOrBasicString |
* |
<optional> |
If this is the only parameter and it is an integer, it is a Unix time and the Date will be created from it. If it is the only parameter and a String, the format must be "2020-Jan-01 00:00:00" or an error will be thrown. If there are any parameters after it, it represents the year of the Date. | |
monthIndex |
integer |
<optional> |
0 | A value from 0 to 11 (not 12) representing the calendar month. |
day |
integer |
<optional> |
1 | The calendar day of month, starting with 1. |
hours |
integer |
<optional> |
0 | The hour of day between 0 and 23. |
minutes |
integer |
<optional> |
0 | The minutes of the hour between 0 and 59. |
seconds |
integer |
<optional> |
0 | The seconds of the minute, between 0 and 59. |
milliseconds |
integer |
<optional> |
0 | The milliseconds of the second, between 0 and 999. |
Methods
(static) now() → {integer}
Returns the number of milliseconds elapsed since January 1st, 1970.
Returns:
See description
- Type
- integer
getDate() → {integer}
Get the day of the month starting with 1 as the lowest possible value.
Returns:
The calendar day of month.
- Type
- integer
getDay() → {integer}
Gets the day of the week starting with 0 for Sunday
Returns:
An integer beween 0 and 6 representing the day of the week.
- Type
- integer
getFullYear() → {integer}
Gets the year of the Date
Returns:
The year.
- Type
- integer
getHours() → {integer}
Gets the hour of the day.
Returns:
An integer between 0 and 23 representing the hour of the Date
- Type
- integer
getMilliseconds() → {integer}
Gets the milliseconds of the Date
Returns:
An integer between 0 and 999 representing the milliseconds of the Date
- Type
- integer
getMinutes() → {integer}
Get the minutes of the Date
Returns:
An integer between 0 and 59 representing the minutes of the Date
- Type
- integer
getSeconds() → {integer}
Get the seconds of the Date
Returns:
An integer between 0 and 59 representing the seconds of the Date
- Type
- integer
getTime() → {integer}
Returns the current Date's Unix time representation.
Returns:
The Unix time, but the last 3 digits are imprecise.
- Type
- integer
getTimezone() → {integer}
Returns the UTC timezone offset of the Date. Dates are created with timezones local to the host machine.
Returns:
The number of minutes the Date is offset to UTC time.
- Type
- integer
setDate(d)
Sets the day of month, starting with 1. This value has to be valid according to the Date's calendar
month or it throws an error.
Parameters:
Name | Type | Description |
---|---|---|
d |
integer | A number starting at 1 and not exceeding the Date's calendar month's days |
setFullYear(year)
Sets the year of the Date
Parameters:
Name | Type | Description |
---|---|---|
year |
integer | The year to set the Date to |
setHours(hours, minutesopt, secondsopt)
Sets the hour, and optionally the minute or second of the Date.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hours |
integer | A number from 0 to 23. This value will be clamped if out of range. | ||
minutes |
integer |
<optional> |
0 | A number from 0 to 59. This value will be clamped if out of range. |
seconds |
integer |
<optional> |
0 | A number from 0 to 59. This value will be clamped if out of range. |
setMilliseconds(ms)
Set the milliseconds of the Date
Parameters:
Name | Type | Description |
---|---|---|
ms |
integer | A number from 0 to 999. This value will be clamped if out of range. |
setMinutes(minutes)
Set the minutes of the Date
Parameters:
Name | Type | Description |
---|---|---|
minutes |
integer | A number from 0 to 59. This value will be clamped if out of range. |
setMonth(month)
Set the month of the Date
Parameters:
Name | Type | Description |
---|---|---|
month |
integer | A number from 0 to 11. This value will be clamped if out of range. |
setSeconds(s)
Set the seconds of the Date
Parameters:
Name | Type | Description |
---|---|---|
s |
integer | A number from 0 to 59. This value will be clamped if out of range. |
setTime(unixTimeMs)
Set the Date to a Unix time value.
Parameters:
Name | Type | Description |
---|---|---|
unixTimeMs |
integer | A Unix time integer |
toISOString() → {String}
Get an ISO representation of the Date as a String
Returns:
ISO representation of the Date
- Type
- String
toUTC() → {Date}
Convert a Date to UTC format
Returns:
A new Date object stored as UTC time.
- Type
- Date