Date object

Represents date and time. Local and UTC timezones supported.

Properties

local time

day
- integer, number of the day, from 1 up to number of days in current month. Read/write property.
month
- integer, number of the month, from 1 to 12. Read/write property.
year
- integer, full number of the year, e.g. 2005. Read/write property.
hour
- integer, hour, from 0 to 23. Read/write property.
minute
- integer, minute, from 0 to 59. Read/write property.
second
- integer, second, from 0 to 59. Read/write property.
millisecond
- integer, millisecond, from 0 to 999. Read/write property.
dayOfWeek
- integer, number of day of the week, from 0 to 6 where 0 is Monday. Read-only property.
firstDayOfWeek
- integer, from 0 to 6 where 0 is Monday - first day of the week in current locale. Read-only class property that can be used as Date.firstDayOfWeek.

UTC time

UTCday
- integer, number of the day, from 1 up to number of days in current month. Read/write property.
UTCmonth
- integer, number of the month, from 1 to 12. Read/write property.
UTCyear
- integer, full number of the year, e.g. 2005. Read/write property.
UTChour
- integer, hour, from 0 to 23. Read/write property.
UTCminute
- integer, minute, from 0 to 59. Read/write property.
UTCsecond
- integer, second, from 0 to 59. Read/write property.
UTCmillisecond
- integer, millisecond, from 0 to 999. Read/write property.
UTCdayOfWeek
- integer, number of day of the week, from 0 to 6 where 0 is Monday. Read-only property.

Methods

[new Date]

( [string| float | Date | [ year, month, day [, hour [, minute [, second [, millisecond ]]]]]] )

Creates new date object. If no parameters were given then initializes date fields to the current time(UTC).
If single string parameter provided then parses date contained in the string.
If single float parameter provided then it is treated as number of milliseconds since midnight, January 1, 1970 UTC.
If single Date parameter provided then copy of that date object is created.
And if year, month, day, etc. provided uses these numeric values to initialize new Date instance. Note: values are in UTC timezone.

new Date(string) form recognizes date in RFC-822 date format ( http://www.w3.org/Protocols/rfc822/#z28 ) and ISO 8601 ( http://www.w3.org/TR/NOTE-datetime ).

utc

( year, month, day [, hour [, minute [, second [, millisecond ]]]]] )

Static method, constructs new date object from year, month, day, etc.

Note: values are in UTC timezone.

Use it as var date = Date.utc(1999,1,1);

local

( year, month, day [, hour [, minute [, second [, millisecond ]]]]] )

Static method, constructs new date object from year, month, day, etc.  

Note: values are in local timezone .

Use it as var date = Date.local(1999,1,1);

toString
( [format:string [, utc:bool ]]) : string

By default it returns RFC-822 string representation of this date object. 

If format is provided then it gets interpreted by strftime rules.

If utc is provided and is true then formatting is made without local timezone shift.  

toUTCString
() : string

Returns RFC-822 string representation of this date object as UTC date/time.

toISOString
( [asUTC: false|true ] )

Returns ISO 8601 string representation of this date object as either local or UTC date/time.

toLocaleString

( [longFormat:false|true[, andTime:false|true]] ) returns: string

Returns string representation of the date using current system settings. Local time.

If longFormat is equal exactly true then formats date using system long date format.

If andTime is true then result string will also contain time.

valueOf
() returns: float

Returns stored time value in milliseconds since midnight, January 1, 1970 UTC.

parse

( string ) returns: float | undefined

Static method. Tries to parse date in string. If result of parsing is successful then returns date as number of milliseconds since midnight, January 1, 1970 UTC.
On error returns undefiend value.

UTC

( year, month, day [, hour [, minute [, second [, millisecond ]]]]] ) returns: float | undefined

Static method. Returns number of milliseconds since midnight, January 1, 1970 UTC up to date defined by parameters

setTime

( milliseconds ) returns: float

Sets this date object fields equal to date defined by milliseconds parameter. milliseconds is a number (float) of milliseconds since midnight, January 1, 1970 UTC.

monthName
( longFormat ) returns: string

Returns name of the month in current user's locale. If longFormat is equal true returns full month name, otherwise - it's abbreviation.

dayOfWeekName
( longFormat ) returns: string

Returns name of the day in current user's locale. If longFormat is equal true returns full week day name, otherwise - it's abbreviation.

isDaylight
( ) : true | false

Returns true if current clock is using daylight saving time.

timeZoneOffset
( ) : integer

Returns shift in milliseconds of current timezone from GMT.

timeZoneName
( ) : string

Returns name of current timezone.

diff
(d1: Date, d2: Date, what: #years | #months | #days | #hours | #minutes | #sconds)

Returns calendar difference between two dates so 

Date.diff(new Date(2019,8,31),new Date(2019,9,1),#days) == 1;
Date.diff(new Date(2019,8,31),new Date(2019,9,1),#months) == 1; // first date is in previous month from second one