Date

Moduleejs
Definitionfinal class Date
InheritanceDate inherit Object
StabilityEvolving.

General purpose class for representing and working with dates, times, time spans and time zones.


Properties

QualifiersPropertyTypeDescription
public get setdateNumberThe day of the month (1-31). If a value outside the range is given, the date is adjusted without error.
public get setdayNumberThe day of the week (0 - 6, where 0 is Sunday) in local time. If a value outside the range is given, the date is adjusted without error.
public get setdayOfYearNumberThe day of the year (0 - 365) in local time. If a value outside the range is given, the date is adjusted without error.
public get elapsedNumberTime in milliseconds since the date object was constructed.
public get sethoursNumberThe current hour (0 - 23) in local time. If a value outside the range is given, the date is adjusted without error.
public get setmillisecondsNumberThe current millisecond (0 - 999) in local time. If a value outside the range is given, the date is adjusted without error.
public get setminutesNumberThe current minute (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
public get setmonthNumberThe current month (0 - 11) in local time. If a value outside the range is given, the date is adjusted without error.
public get setsecondsNumberThe current second (0 - 59) in local time. If a value outside the range is given, the date is adjusted without error.
public get settimeNumberThe number of milliseconds since midnight, January 1st, 1970 UTC and the current date object. This is the same as Date.now().
public get setyearNumberThe year in local time. This is the full year. E.g. A date of the year 2010 will return the number 2010.

Date Methods

QualifiersMethod
Date(args: Array)
 Construct a new date object.
public format(layout: String): String
 Format a date using a format specifier in local time.
public formatUTC(layout: String): String
 Format a date using a format specifier in UTC time.
public getDate(): Number
 Return the day of the month in local time.
public getDay(): Number
 Return the day of the week in local time.
public getFullYear(): Number
 Return the year as four digits in local time.
public getHours(): Number
 Return the hour (0 - 23) in local time.
public getMilliseconds(): Number
 Return the millisecond (0 - 999) in local time.
public getMinutes(): Number
 Return the minute (0 - 59) in local time.
public getMonth(): Number
 Return the month (0 - 11) in local time.
public getSeconds(): Number
 Return the second (0 - 59) in local time.
public getTime(): Number
 Return the number of milliseconds since midnight, January 1st, 1970 UTC.
public getTimezoneOffset(): Number
 Return the number of minutes between the local computer time and Coordinated Universal Time.
public getUTCDate(): Number
 Return the day (date) of the month (1 - 31) in UTC time.
public getUTCDay(): Number
 Return the day of the week (0 - 6) in UTC time.
public getUTCFullYear(): Number
 Return the year in UTC time.
public getUTCHours(): Number
 Return the hour (0 - 23) in UTC time.
public getUTCMilliseconds(): Number
 Return the millisecond (0 - 999) in UTC time.
public getUTCMinutes(): Number
 Return the minute (0 - 59) in UTC time.
public getUTCMonth(): Number
 Return the month (1 - 12) in UTC time.
public getUTCSeconds(): Number
 Return the second (0 - 59) in UTC time.
public nanoAge(): Number
 Time in nanoseconds since the date object was constructed.
public nextDay(inc: Number = 1): Date
 Return a new Date object that is one day greater than this one.
public static now(): Number
 Return the current time as milliseconds since Jan 1 1970.
public static parse(dateString: String): Number
 Parse a date string and return the number of milliseconds since midnight, January 1st, 1970 UTC.
public static parseDate(dateString: String, defaultDate: Date = null): Date
 Parse a date string and Return a new Date object.
public static parseUTCDate(dateString: String, defaultDate: Date = null): Date
 Parse a date string and Return a new Date object.
public setDate(d: Number): Void
 Set the date of the month (1 - 31) If a value outside the range is given, the date is adjusted without error.
public setFullYear(y: Number): Void
 Set the current year as four digits in local time.
public setHours(h: Number): Void
 Set the current hour (0 - 23) in local time.
public setMilliseconds(ms: Number): Void
 Set the current millisecond (0 - 999) in local time.
public setMinutes(min: Number): Void
 Set the current minute (0 - 59) in local time.
public setMonth(mon: Number): Void
 Set the current month (0 - 11) in local time.
public setSeconds(sec: Number, msec: Number = null): Void
 Set the current second (0 - 59) in local time.
public setTime(value: Number): Void
 Set the number of milliseconds since midnight, January 1st, 1970 UTC.
public setUTCDate(d: Number): Void
 Set the date of the month (0 - 31) in UTC time.
public setUTCFullYear(y: Number): Void
 Set the current year as four digits in UTC time.
public setUTCHours(h: Number): Void
 Set the current hour (0 - 23) in UTC time.
public setUTCMilliseconds(ms: Number): Void
 Set the current millisecond (0 - 999) in UTC time.
public setUTCMinutes(min: Number): Void
 Set the current minute (0 - 59) in UTC time.
public setUTCMonth(mon: Number): Void
 Set the current month (0 - 11) in UTC time.
public setUTCSeconds(sec: Number, msec: Number = null): Void
 Set the current second (0 - 59) in UTC time.
public toDateString(): String
 Return a string containing the date portion excluding the time portion of the date in local time.
public toISOString(): String
 Return an ISO formatted date string.
public override toJSON(): String
 Convert a date to an equivalent JSON encoding.
public toLocaleDateString(): String
 Return a localized string containing the date portion excluding the time portion of the date in local time.
public toLocaleString(): String
 Return a localized string containing the date.
public toLocaleTimeString(): String
 Return a string containing the time portion of the date in local time.
public override toString(): String
 Return a string representing the date in local time.
public toTimeString(): String
 Return a string containing the time portion in human readable form in American English.
public toUTCString(): String
 Return a string containing the date in UTC time.
public static UTC(year: Number, month: Number, day: Number, hours: Number = 0 , minutes: Number = 0 , seconds: Number = 0 , milliseconds: Number = 0): Number
 Calculate the number of milliseconds since the epoch for a UTC time.
public valueOf(): Number
 Return the primitive value of the object.

Method Detail

public Date(args: Array)

Construct a new date object.

Description
Permissible constructor forms:
  • Date() This is the default and it constructs a date instance for the current time.
  • Date(milliseconds) where (seconds sincde 1 Jan 1970 00:00:00 UTC))
  • Date(dateString) where (In a format recognized by parse())
  • Date(year, month, date) where (Four digit year, month: 0-11, date: 1-31)
  • Date(year, month, date [, hour, minute, second, msec]) where (hour: 0-23, minute: 0-59, second: 0-59, msec: 0-999)

public format(layout: String): String

Format a date using a format specifier in local time.

Description
This routine is implemented by calling the O/S strftime routine and so not all the format specifiers are available on all platforms. For full details, consult your platform API manual for strftime.

The format specifiers are:
  • %A national representation of the full weekday name.
  • %a national representation of the abbreviated weekday name.
  • %B national representation of the full month name.
  • %b national representation of the abbreviated month name.
  • %C (year / 100) as decimal number; single digits are preceded by a zero.
  • %c national representation of time and date.
  • %D is equivalent to %m/%d/%y.
  • %d the day of the month as a decimal number (01-31).
  • %e the day of month as a decimal number (1-31); single digits are preceded by a blank.
  • %F is equivalent to %Y-%m-%d.
  • %H the hour (24-hour clock) as a decimal number (00-23).
  • %h the same as %b.
  • %I the hour (12-hour clock) as a decimal number (01-12).
  • %j the day of the year as a decimal number (001-366). Note: this range is different to that of the dayOfYear property which is 0-365.
  • %k the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank.
  • %l the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank.
  • %M the minute as a decimal number (00-59).
  • %m the month as a decimal number (01-12).
  • %n a newline.
  • %P Lower case national representation of either "ante meridiem" or "post meridiem" as appropriate.
  • %p national representation of either "ante meridiem" or "post meridiem" as appropriate.
  • %R is equivalent to %H:%M.
  • %r is equivalent to %I:%M:%S %p.
  • %S the second as a decimal number (00-60).
  • %s the number of seconds since the January 1, 1970 UTC.
  • %T is equivalent to %H:%M:%S.
  • %t a tab.
  • %U the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).
  • %u the weekday (Monday as the first day of the week) as a decimal number (1-7).
  • %v is equivalent to %e-%b-%Y.
  • %W the week number of the year (Monday as the first day of the week) as a decimal number (00-53).
  • %w the weekday (Sunday as the first day of the week) as a decimal number (0-6).
  • %X national representation of the time.
  • %x national representation of the date.
  • %Y the year with century as a decimal number.
  • %y the year without century as a decimal number (00-99).
  • %Z the time zone name.
  • %z the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).
  • %+ national representation of the date and time (the format is similar to that produced by date(1)). This format is platform dependent.
  • %% Literal percent.


Some platforms may also support the following format extensions:
  • %E* POSIX locale extensions. Where "*"" is one of the characters: c, C, x, X, y, Y.
  • %G a year as a decimal number with century. This year is the one that contains the greater part of the week (Monday as the first day of the week).
  • %g the same year as in %G, but as a decimal number without century (00-99).
  • %O* POSIX locale extensions. Where "*"" is one of the characters: d e H I m M S u U V w W y. supposed to provide alternate representations. Additionly %OB implemented to represent alternative months names (used standalone, without day mentioned).
  • %V the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1.
Parameters
layout: String Format layout string using the above format specifiers. See strftime(3) for more information.
Returns
String representation of the date.
Specified
ejscript-1.1

public formatUTC(layout: String): String

Format a date using a format specifier in UTC time.

Description
This routine is implemented by calling the O/S strftime routine and so not all the format specifiers are available on all platforms.
Parameters
layout: String Format layout string using the above format specifiers. See format() for the list of format specifiers.
Returns
String representation of the date.
Specified
ejscript-1.1

public getDate(): Number

Return the day of the month in local time.

Returns
Returns the day of the year (1-31).

public getDay(): Number

Return the day of the week in local time.

Returns
The integer day of the week (0 - 6, where 0 is Sunday).

public getFullYear(): Number

Return the year as four digits in local time.

Returns
The integer year.

public getHours(): Number

Return the hour (0 - 23) in local time.

Returns
The integer hour of the day.

public getMilliseconds(): Number

Return the millisecond (0 - 999) in local time.

Returns
The number of milliseconds as an integer.

public getMinutes(): Number

Return the minute (0 - 59) in local time.

Returns
The number of minutes as an integer.

public getMonth(): Number

Return the month (0 - 11) in local time.

Returns
The month number as an integer.

public getSeconds(): Number

Return the second (0 - 59) in local time.

Returns
The number of seconds as an integer.

public getTime(): Number

Return the number of milliseconds since midnight, January 1st, 1970 UTC.

Returns
The number of milliseconds as a long.

public getTimezoneOffset(): Number

Return the number of minutes between the local computer time and Coordinated Universal Time.

Returns
Integer containing the number of minutes between UTC and local time. The offset is positive if local time is behind UTC and negative if it is ahead. E.g. American PST is UTC-8 so 480 will be retured. This value will vary if daylight savings time is in effect.

public getUTCDate(): Number

Return the day (date) of the month (1 - 31) in UTC time.

Returns
The day of the month as an integer.

public getUTCDay(): Number

Return the day of the week (0 - 6) in UTC time.

Returns
The day of the week as an integer.

public getUTCFullYear(): Number

Return the year in UTC time.

Returns
The full year in 4 digits as an integer.

public getUTCHours(): Number

Return the hour (0 - 23) in UTC time.

Returns
The integer hour of the day.

public getUTCMilliseconds(): Number

Return the millisecond (0 - 999) in UTC time.

Returns
The number of milliseconds as an integer.

public getUTCMinutes(): Number

Return the minute (0 - 59) in UTC time.

Returns
The number of minutes as an integer.

public getUTCMonth(): Number

Return the month (1 - 12) in UTC time.

Returns
The month number as an integer.

public getUTCSeconds(): Number

Return the second (0 - 59) in UTC time.

Returns
The number of seconds as an integer.

public nanoAge(): Number

Time in nanoseconds since the date object was constructed.

Specified
ejscript-1.1

public nextDay(inc: Number = 1): Date

Return a new Date object that is one day greater than this one.

Parameters
inc: Number Increment in days to add (or subtract if negative). [default: 1]
Returns
A Date object.
Specified
ejscript-1.1

static public now(): Number

Return the current time as milliseconds since Jan 1 1970.

Specified
mozilla

static public parse(dateString: String): Number

Parse a date string and return the number of milliseconds since midnight, January 1st, 1970 UTC.

Description
If dateString does not contain a timezone, the date string will be interpreted as a local date/time.
Parameters
dateString: String The string to parse. See parseDate for supported formats.
Returns
Return a new date number.

static public parseDate(dateString: String, defaultDate: Date = null): Date

Parse a date string and Return a new Date object.

Description
If dateString does not contain a timezone, the date string will be interpreted as a local date/time. This is similar to parse() but it returns a date object.
Parameters
dateString: String The date string to parse. The date parsing logic uses heuristics and attempts to intelligently parse a range of dates. Some of the possible formats are:
  • 07/28/2012
  • 07/28/08
  • Jan/28/2012
  • Jaunuary-28-2012
  • 28-jan-2012
  • [29] Jan [15] [2012]
  • dd/mm/yy, dd.mm.yy, dd-mm-yy
  • mm/dd/yy, mm.dd.yy, mm-dd-yy
  • yyyy/mm/dd, yyyy.mm.dd, yyyy-mm-dd
  • 10:52[:23]
  • 2009-05-21t16:06:05.000z (ISO date)
  • [GMT|UTC][+-]NN[:]NN (timezone)
defaultDate: Date Default date to use to fill out missing items in the date string. [default: null]
Returns
Return a new Date.
Specified
ejscript-1.1

static public parseUTCDate(dateString: String, defaultDate: Date = null): Date

Parse a date string and Return a new Date object.

Description
If dateString does not contain a timezone, the date string will be interpreted as a UTC date/time.
Parameters
dateString: String UTC date string to parse. See parseDate for supported formats.
defaultDate: Date Default date to use to fill out missing items in the date string. [default: null]
Returns
Return a new Date.
Specified
ejscript-1.1

public setDate(d: Number): Void

Set the date of the month (1 - 31) If a value outside the range is given, the date is adjusted without error.

Parameters
d: Number Date of the month.

public setFullYear(y: Number): Void

Set the current year as four digits in local time.

Parameters
y: Number Current year.

public setHours(h: Number): Void

Set the current hour (0 - 23) in local time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
h: Number The hour as an integer.

public setMilliseconds(ms: Number): Void

Set the current millisecond (0 - 999) in local time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
ms: Number The millisecond as an integer.

public setMinutes(min: Number): Void

Set the current minute (0 - 59) in local time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
min: Number The minute as an integer.

public setMonth(mon: Number): Void

Set the current month (0 - 11) in local time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
mon: Number The month as an integer.

public setSeconds(sec: Number, msec: Number = null): Void

Set the current second (0 - 59) in local time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
sec: Number The second as an integer.
msec: Number Optional milliseconds as an integer. [default: null]

public setTime(value: Number): Void

Set the number of milliseconds since midnight, January 1st, 1970 UTC.

Parameters
value: Number The millisecond as a long.

public setUTCDate(d: Number): Void

Set the date of the month (0 - 31) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
d: Number The date to set.

public setUTCFullYear(y: Number): Void

Set the current year as four digits in UTC time.

Parameters
y: Number The year to set.

public setUTCHours(h: Number): Void

Set the current hour (0 - 23) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
h: Number The hour as an integer.

public setUTCMilliseconds(ms: Number): Void

Set the current millisecond (0 - 999) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
ms: Number The millisecond as an integer.

public setUTCMinutes(min: Number): Void

Set the current minute (0 - 59) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
min: Number The minute as an integer.

public setUTCMonth(mon: Number): Void

Set the current month (0 - 11) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
mon: Number The month as an integer.

public setUTCSeconds(sec: Number, msec: Number = null): Void

Set the current second (0 - 59) in UTC time.

Description
If a value outside the range is given, the date is adjusted without error.
Parameters
sec: Number The second as an integer.
msec: Number Optional milliseconds as an integer. [default: null]

public toDateString(): String

Return a string containing the date portion excluding the time portion of the date in local time.

Description
The format is American English. Sample: "Fri Jan 15 2012".
Returns
A string representing the date portion.

public toISOString(): String

Return an ISO formatted date string.

Description
Sample: "2006-12-15T23:45:09.33-08:00".
Returns
An ISO formatted string representing the date.
Specified
ejscript-1.1

override public toJSON(): String

Convert a date to an equivalent JSON encoding.

Returns
This function returns a date in ISO format as a string.
Throws
TypeError: If the object could not be converted to a string.

public toLocaleDateString(): String

Return a localized string containing the date portion excluding the time portion of the date in local time.

Description
Note: You should not rely on the format of the output as the exact format will depend on the platform and locale. Sample: "Fri 15 Dec 2006 GMT-0800". (Note: Other platforms render as: V8 format: "Fri, 15 Dec 2006 GMT-0800" JS format: "01/15/2012" JSC format: "January 15, 2012").
Returns
A string representing the date portion.

public toLocaleString(): String

Return a localized string containing the date.

Description
This formats the date using the operating system's locale conventions. Sample: "Fri 15 Dec 2006 23:45:09 GMT-0800 (PST)". (Note: Other JavaScript platforms render as: V8 format: "Fri, 15 Dec 2006 23:45:09 GMT-0800 (PST)" JS format: "Fri Jan 15 13:09:02 2012" JSC format: "January 15, 2012 1:09:06 PM PST".
Returns
A string representing the date.

public toLocaleTimeString(): String

Return a string containing the time portion of the date in local time.

Description
Sample: "13:08:57". Note: Other JavaScript platforms render as: V8 format: "13:08:57" JS format: "13:09:02" JSC format: "1:09:06 PM PST".
Returns
A string representing the time.

override public toString(): String

Return a string representing the date in local time.

Description
The format is American English. Sample: "Fri 15 Dec 2006 23:45:09 GMT-0800 (PST)".
Returns
A string representing the date.

public toTimeString(): String

Return a string containing the time portion in human readable form in American English.

Description
Sample: "13:08:57 GMT-0800 (PST)".
Returns
A string representing the time.

public toUTCString(): String

Return a string containing the date in UTC time.

Description
Sample: "Sat 16 Dec 2006 08:06:21 GMT".
Returns
A string representing the date.

static public UTC(year: Number, month: Number, day: Number, hours: Number = 0 , minutes: Number = 0 , seconds: Number = 0 , milliseconds: Number = 0): Number

Calculate the number of milliseconds since the epoch for a UTC time.

Description
Date(year, month, date [, hour, minute, second, msec])
Parameters
year: Number Year.
month: Number Month of year.
day: Number Day of month.
hours: Number Hour of day. [default: 0 ]
minutes: Number Minute of hour. [default: 0 ]
seconds: Number Secods of minute. [default: 0 ]
milliseconds: Number Milliseconds of second. [default: 0]
Returns
The number of milliseconds since January 1, 1970 00:00:00 UTC.

public valueOf(): Number

Return the primitive value of the object.

Returns
A number corresponding to the $time property.